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): update selectedItems property on all item selection changes #7204

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/calcite-components/src/components/list/list.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
12 changes: 7 additions & 5 deletions packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
driskull marked this conversation as resolved.
Show resolved Hide resolved
listItems.forEach((listItem) => {
if (selectionMode === "single" || selectionMode === "single-persist") {
listItem.selected = listItem === target;
}
});
}

this.updateSelectedItems();
}
Expand Down