Skip to content

Commit b7edfdc

Browse files
anveshmekalabenelan
authored andcommitted
fix(list-item): adds border between grouped and ungrouped list-items (#8134)
**Related Issue:** #7546 Adds border to the `calcite-list-item` excluding the first `calcite-list-item` in the `calcite-list-item-group` or the `calcite-list`.
1 parent 963195e commit b7edfdc

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

packages/calcite-components/calcite-preset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export default {
165165
"2-lg": "var(--calcite-box-shadow-md)",
166166
"2-sm": "0 2px 12px -4px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.16)",
167167
"border-bottom": "0 1px 0 var(--calcite-color-border-3)",
168+
"border-top": "0 -1px 0 var(--calcite-color-border-3)",
168169
"outline-active": "0 0 0 1px var(--calcite-color-brand)",
169170
none: "none",
170171
xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",

packages/calcite-components/src/components/list-item-group/list-item-group.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
}
1717

1818
::slotted(calcite-list-item) {
19-
@apply shadow-border-bottom mb-px;
19+
@apply shadow-border-top;
20+
margin-block-start: 1px;
2021
}
2122

22-
::slotted(calcite-list-item:last-child) {
23+
// removes shadow for the first item of the group for both filtered and unfiltered items.
24+
::slotted(calcite-list-item:nth-child(1 of :not([hidden]))) {
2325
@apply shadow-none;
26+
margin-block-start: 0px;
2427
}
2528

2629
@include base-component();

packages/calcite-components/src/components/list/list.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@
2929
}
3030

3131
::slotted(calcite-list-item) {
32-
@apply shadow-border-bottom mb-px;
32+
@apply shadow-border-top;
33+
margin-block-start: 1px;
3334
}
3435

35-
::slotted(calcite-list-item:last-child) {
36+
::slotted(calcite-list-item:first-of-type) {
3637
@apply shadow-none;
3738
}
3839

40+
// removes shadow for the first item in filteredItems of the list.
41+
::slotted(calcite-list-item[data-filter]) {
42+
@apply shadow-none;
43+
margin-block-start: 0px;
44+
}
45+
3946
.sticky-pos {
4047
@apply sticky
4148
top-0

packages/calcite-components/src/components/list/list.stories.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export const closableListItems_TestOnly = (): string => html`<calcite-list
448448
</calcite-list-item>
449449
</calcite-list>`;
450450

451-
export const filteredChildListItems_TestOnly = (): string => html` <calcite-list
451+
export const filteredChildListItems_TestOnly = (): string => html`<calcite-list
452452
filter-enabled
453453
filter-text="est"
454454
filter-placeholder="Find content"
@@ -630,6 +630,10 @@ export const filteredChildListItems_TestOnly = (): string => html` <calcite-list
630630
</calcite-list-item-group>
631631
</calcite-list>`;
632632

633+
filteredChildListItems_TestOnly.parameters = {
634+
chromatic: { delay: 1000 },
635+
};
636+
633637
export const filterActions_TestOnly = (): string => html`<calcite-list
634638
selection-mode="single"
635639
label="test"

packages/calcite-components/src/components/list/list.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo
360360

361361
sortable: Sortable;
362362

363+
private ancestorOfFirstFilteredItem: HTMLCalciteListItemElement;
364+
363365
// --------------------------------------------------------------------------
364366
//
365367
// Public Methods
@@ -579,6 +581,10 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo
579581
this.filterElements({ el: listItem, filteredItems, visibleParents })
580582
);
581583

584+
if (filteredItems.length > 0) {
585+
this.findAncestorOfFirstFilteredItem(filteredItems);
586+
}
587+
582588
this.filteredItems = filteredItems;
583589

584590
if (emit) {
@@ -742,6 +748,35 @@ export class List implements InteractiveComponent, LoadableComponent, SortableCo
742748
}
743749
};
744750

751+
private findAncestorOfFirstFilteredItem = (filteredItems: HTMLCalciteListItemElement[]): void => {
752+
this.ancestorOfFirstFilteredItem?.removeAttribute("data-filter");
753+
filteredItems.forEach((item) => {
754+
item.removeAttribute("data-filter");
755+
});
756+
757+
this.ancestorOfFirstFilteredItem = this.getTopLevelAncestorItemElement(filteredItems[0]);
758+
filteredItems[0].setAttribute("data-filter", "0");
759+
this.ancestorOfFirstFilteredItem?.setAttribute("data-filter", "0");
760+
};
761+
762+
private getTopLevelAncestorItemElement = (
763+
el: HTMLCalciteListItemElement
764+
): HTMLCalciteListItemElement | null => {
765+
let closestParent = el.parentElement.closest<HTMLCalciteListItemElement>("calcite-list-item");
766+
767+
while (closestParent) {
768+
const closestListItemAncestor =
769+
closestParent.parentElement.closest<HTMLCalciteListItemElement>("calcite-list-item");
770+
771+
if (closestListItemAncestor) {
772+
closestParent = closestListItemAncestor;
773+
} else {
774+
return closestParent;
775+
}
776+
}
777+
return null;
778+
};
779+
745780
handleNudgeEvent(event: CustomEvent<HandleNudge>): void {
746781
const { direction } = event.detail;
747782

0 commit comments

Comments
 (0)