From ab7b496bf494206130843ca11f0265bc05c0e317 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Tue, 20 Jun 2023 16:28:13 -0700 Subject: [PATCH 1/3] fix(list): update selectedItems property on all item selection changes. #7202 --- .../src/components/list-item/list-item.tsx | 6 ++---- .../src/components/list/list.e2e.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/calcite-components/src/components/list-item/list-item.tsx b/packages/calcite-components/src/components/list-item/list-item.tsx index 8a88d94b3e3..2a640e48c65 100644 --- a/packages/calcite-components/src/components/list-item/list-item.tsx +++ b/packages/calcite-components/src/components/list-item/list-item.tsx @@ -131,10 +131,8 @@ export class ListItem @Prop({ reflect: true, mutable: true }) selected = false; @Watch("selected") - handleSelectedChange(value: boolean): void { - if (value) { - this.calciteInternalListItemSelect.emit(); - } + handleSelectedChange(): void { + this.calciteInternalListItemSelect.emit(); } /** diff --git a/packages/calcite-components/src/components/list/list.e2e.ts b/packages/calcite-components/src/components/list/list.e2e.ts index 5d4a14b541a..c05574f4285 100755 --- a/packages/calcite-components/src/components/list/list.e2e.ts +++ b/packages/calcite-components/src/components/list/list.e2e.ts @@ -328,5 +328,17 @@ describe("calcite-list", () => { await calciteListChangeEvent2; expect(await listItemOne.getProperty("selected")).toBe(false); expect(await list.getProperty("selectedItems")).toHaveLength(0); + + listItemOne.setProperty("selected", true); + await page.waitForChanges(); + await page.waitForTimeout(listDebounceTimeout); + expect(await listItemOne.getProperty("selected")).toBe(true); + expect(await list.getProperty("selectedItems")).toHaveLength(1); + + listItemOne.setProperty("selected", false); + await page.waitForChanges(); + await page.waitForTimeout(listDebounceTimeout); + expect(await listItemOne.getProperty("selected")).toBe(false); + expect(await list.getProperty("selectedItems")).toHaveLength(0); }); }); From 814f26079a2da78c24988c3f0c49dab3dc999e52 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Tue, 20 Jun 2023 16:54:14 -0700 Subject: [PATCH 2/3] fix --- .../calcite-components/src/components/list/list.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/calcite-components/src/components/list/list.tsx b/packages/calcite-components/src/components/list/list.tsx index fca1e5dae50..cfe291971a6 100755 --- a/packages/calcite-components/src/components/list/list.tsx +++ b/packages/calcite-components/src/components/list/list.tsx @@ -185,11 +185,13 @@ export class List implements InteractiveComponent, LoadableComponent { const target = event.target as HTMLCalciteListItemElement; const { listItems, selectionMode } = this; - listItems.forEach((listItem) => { - if (selectionMode === "single" || selectionMode === "single-persist") { - listItem.selected = listItem === target; - } - }); + if (target.selected) { + listItems.forEach((listItem) => { + if (selectionMode === "single" || selectionMode === "single-persist") { + listItem.selected = listItem === target; + } + }); + } this.updateSelectedItems(); } From 235ca4249e141ecdf58a4d7acb6f721912d88d28 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Tue, 20 Jun 2023 17:20:30 -0700 Subject: [PATCH 3/3] review fix cleanup --- packages/calcite-components/src/components/list/list.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/calcite-components/src/components/list/list.tsx b/packages/calcite-components/src/components/list/list.tsx index cfe291971a6..41cc08d8a40 100755 --- a/packages/calcite-components/src/components/list/list.tsx +++ b/packages/calcite-components/src/components/list/list.tsx @@ -185,12 +185,8 @@ export class List implements InteractiveComponent, LoadableComponent { const target = event.target as HTMLCalciteListItemElement; const { listItems, selectionMode } = this; - if (target.selected) { - listItems.forEach((listItem) => { - if (selectionMode === "single" || selectionMode === "single-persist") { - listItem.selected = listItem === target; - } - }); + if (target.selected && (selectionMode === "single" || selectionMode === "single-persist")) { + listItems.forEach((listItem) => (listItem.selected = listItem === target)); } this.updateSelectedItems();