Skip to content

Commit

Permalink
fix(list): Don't require filterEnabled for filterPredicate usage (#…
Browse files Browse the repository at this point in the history
…11109)

**Related Issue:** #6544

## Summary

- fix to not require filterEnabled to use filterPredicate
- It was basically the `(changes.has("filterPredicate") &&
this.hasUpdated)` that was the culprit.
- add test

BEGIN_COMMIT_OVERRIDE
END_COMMIT_OVERRIDE
  • Loading branch information
driskull authored and benelan committed Feb 8, 2025
1 parent a7dbe1d commit 4f4d79b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
28 changes: 28 additions & 0 deletions packages/calcite-components/src/components/list/list.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,34 @@ describe("calcite-list", () => {
}
});

it("filterPredicate will work without filterEnabled", async () => {
const matchingFont = "Courier";

const page = await newE2EPage();
await page.setContent(html`
<calcite-list>
<calcite-list-item value="item1" label="${matchingFont}" description="list1"></calcite-list-item>
<calcite-list-item value="item2" label="${matchingFont} 2" description="list1"></calcite-list-item>
<calcite-list-item value="item3" label="Other Font" description="list1"></calcite-list-item>
</calcite-list>
`);
await page.waitForChanges();

await page.$eval("calcite-list", (list: List["el"]) => {
list.filterPredicate = (item) => {
return item.value === "item2";
};
});

await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE.filter);

const visibleItems = await page.findAll("calcite-list-item:not([filter-hidden])");

expect(visibleItems).toHaveLength(1);
expect(await visibleItems[0].getProperty("value")).toBe("item2");
});

it("filters initially", async () => {
const page = await newE2EPage();
await page.setContent(html`
Expand Down
20 changes: 9 additions & 11 deletions packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class List
dragEnabled,
el,
filterEl,
filterEnabled,
moveToItems,
displayMode,
scale,
Expand Down Expand Up @@ -129,7 +128,7 @@ export class List
}

this.listItems = items;
if (filterEnabled && this.willPerformFilter) {
if (this.filterEnabled && this.willPerformFilter) {
this.willPerformFilter = false;
this.dataForFilter = this.getItemData();

Expand Down Expand Up @@ -438,7 +437,8 @@ export class List
(changes.has("selectionAppearance") &&
(this.hasUpdated || this.selectionAppearance !== "icon")) ||
(changes.has("displayMode") && this.hasUpdated) ||
(changes.has("scale") && this.hasUpdated)
(changes.has("scale") && this.hasUpdated) ||
(changes.has("filterPredicate") && this.hasUpdated)
) {
this.handleListItemChange();
}
Expand Down Expand Up @@ -814,14 +814,12 @@ export class List
}

private getItemData(): ItemData {
return this.filterPredicate
? []
: this.listItems.map((item) => ({
label: item.label,
description: item.description,
metadata: item.metadata,
el: item,
}));
return this.listItems.map((item) => ({
label: item.label,
description: item.description,
metadata: item.metadata,
el: item,
}));
}

private updateGroupItems(): void {
Expand Down

0 comments on commit 4f4d79b

Please sign in to comment.