diff --git a/packages/calcite-components/src/components/list/list.tsx b/packages/calcite-components/src/components/list/list.tsx index 4db51d740f2..d1a728cbf7b 100755 --- a/packages/calcite-components/src/components/list/list.tsx +++ b/packages/calcite-components/src/components/list/list.tsx @@ -168,6 +168,24 @@ export class List @state() moveToItems: MoveTo[] = []; + @state() get hasActiveFilter(): boolean { + return ( + this.filterEnabled && + this.filterText && + this.filteredItems.length !== this.visibleItems.length + ); + } + + @state() get showNoResultsContainer(): boolean { + return ( + this.filterEnabled && + this.filterText && + this.hasFilterNoResults && + this.visibleItems.length && + !this.filteredItems.length + ); + } + // #endregion // #region Public Properties @@ -187,6 +205,9 @@ export class List /** When `true`, an input appears at the top of the component that can be used by end users to filter `calcite-list-item`s. */ @property({ reflect: true }) filterEnabled = false; + /** todo */ + @property() customFilter: (listItems: ListItem["el"][]) => ListItem["el"][]; + /** Specifies an accessible name for the filter input field. */ @property({ reflect: true }) filterLabel: string; @@ -711,13 +732,18 @@ export class List } private updateFilteredItems(): void { - const { visibleItems, filteredData, filterText } = this; + const { visibleItems, filteredData, filterText, customFilter } = this; const lastDescendantItems = visibleItems?.filter((listItem) => visibleItems.every((li) => li === listItem || !listItem.contains(li)), ); - const filteredItems = !filterText ? visibleItems || [] : filteredData.map((item) => item.el); + const filteredItems = !filterText + ? visibleItems || [] + : customFilter + ? customFilter(visibleItems) + : filteredData.map((item) => item.el); + const visibleParents = new WeakSet(); lastDescendantItems.forEach((listItem) => @@ -785,12 +811,14 @@ export class List } private getItemData(): ItemData { - return this.listItems.map((item) => ({ - label: item.label, - description: item.description, - metadata: item.metadata, - el: item, - })); + return this.customFilter + ? [] + : this.listItems.map((item) => ({ + label: item.label, + description: item.description, + metadata: item.metadata, + el: item, + })); } private updateGroupItems(): void { @@ -994,11 +1022,9 @@ export class List filterEnabled, filterPlaceholder, filterText, - filteredItems, filterLabel, hasFilterActionsStart, hasFilterActionsEnd, - hasFilterNoResults, effectiveFilterProps, } = this; return ( @@ -1057,7 +1083,7 @@ export class List