Skip to content
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

fix(list): Don't require filterEnabled for filterPredicate usage #11109

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading