Skip to content

fix(list-item): adds border between grouped and ungrouped list-items #8134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/calcite-components/calcite-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default {
"2-lg": "0 12px 32px -2px rgba(0, 0, 0, 0.1), 0 4px 20px 0 rgba(0, 0, 0, 0.08)",
"2-sm": "0 2px 12px -4px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.16)",
"border-bottom": "0 1px 0 var(--calcite-ui-border-3)",
"border-top": "0px -1px 0 var(--calcite-ui-border-3)",
"outline-active": "0 0 0 1px var(--calcite-ui-brand)",
none: "none",
xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
}

::slotted(calcite-list-item) {
@apply shadow-border-bottom mb-px;
@apply shadow-border-top;
margin-block-start: 1px;
}

::slotted(calcite-list-item:last-child) {
::slotted(calcite-list-item:first-of-type) {
@apply shadow-none;
}

// removes shadow for the first item in filteredItems of the group.
::slotted(calcite-list-item:nth-child(1 of :not([hidden]))) {
@apply shadow-none;
}

Expand Down
11 changes: 9 additions & 2 deletions packages/calcite-components/src/components/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@
}

::slotted(calcite-list-item) {
@apply shadow-border-bottom mb-px;
@apply shadow-border-top;
margin-block-start: 1px;
}

::slotted(calcite-list-item:last-child) {
::slotted(calcite-list-item:first-of-type) {
@apply shadow-none;
}

// removes shadow for the first item in filteredItems of the list.
::slotted(calcite-list-item[data-filter]) {
@apply shadow-none;
margin-block-start: 0px;
}

.sticky-pos {
@apply sticky
top-0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export const closableListItems_TestOnly = (): string => html`<calcite-list
</calcite-list-item>
</calcite-list>`;

export const filteredChildListItems_TestOnly = (): string => html` <calcite-list
export const filteredChildListItems_TestOnly = (): string => html`<calcite-list
filter-enabled
filter-text="est"
filter-placeholder="Find content"
Expand Down
51 changes: 51 additions & 0 deletions packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo

sortable: Sortable;

private topLevelAncestorsMap = new Map<HTMLCalciteListItemElement, HTMLCalciteListItemElement>();

// --------------------------------------------------------------------------
//
// Public Methods
Expand Down Expand Up @@ -579,6 +581,10 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo
this.filterElements({ el: listItem, filteredItems, visibleParents })
);

if (filteredItems.length > 0) {
this.findAncestorOfFirstFilteredItem(filteredItems);
}

this.filteredItems = filteredItems;

if (emit) {
Expand Down Expand Up @@ -742,6 +748,51 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo
}
};

private findAncestorOfFirstFilteredItem = (filteredItems: HTMLCalciteListItemElement[]): void => {
if (this.topLevelAncestorsMap.size > 0) {
this.topLevelAncestorsMap.forEach(
(value: HTMLCalciteListItemElement, key: HTMLCalciteListItemElement) => {
value.removeAttribute("data-filter");
key.removeAttribute("data-filter");
}
);
this.topLevelAncestorsMap.clear();
}

filteredItems.forEach((item) => {
if (item.hasAttribute("data-filter")) {
item.removeAttribute("data-filter");
}
});

const firstFilteredItem = filteredItems[0];
const topLevelAnchor = this.getTopLevelAncestorItemElement(firstFilteredItem);
if (topLevelAnchor) {
this.topLevelAncestorsMap.set(firstFilteredItem, topLevelAnchor);
}

filteredItems[0].setAttribute("data-filter", "0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally missed this last time, but you can use toggleAttribute if we don't care about the value. Not critical for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can rename the attribute to be something like data-filtered-first so that we can leverage toggleAttribute.

this.topLevelAncestorsMap.get(filteredItems[0])?.setAttribute("data-filter", "0");
};

private getTopLevelAncestorItemElement = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use the walkUpAncestry util for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our convo, we can look at updating some of our dom utils to help cover this use case later (i.e., recursive closest without crossing shadow DOM).

el: HTMLCalciteListItemElement
): HTMLCalciteListItemElement | null => {
let closestParent = el.parentElement.closest("calcite-list-item") as HTMLCalciteListItemElement;

while (closestParent) {
const closestListItemAncestor = closestParent.parentElement.closest(
"calcite-list-item"
) as HTMLCalciteListItemElement;
if (closestListItemAncestor) {
closestParent = closestListItemAncestor;
} else {
return closestParent;
}
}
return null;
};

handleNudgeEvent(event: CustomEvent<HandleNudge>): void {
const { direction } = event.detail;

Expand Down