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(tree): fix item selection when multi + input-enabled #2555

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
2 changes: 1 addition & 1 deletion src/components/calcite-tree-item/calcite-tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class CalciteTreeItem {
}
this.expanded = !this.expanded;
this.calciteTreeItemSelect.emit({
modifyCurrentSelection: (e as any).shiftKey,
modifyCurrentSelection: (e as any).shiftKey || this.inputEnabled,
forceToggle: false
});
}
Expand Down
41 changes: 41 additions & 0 deletions src/components/calcite-tree/calcite-tree.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,47 @@ describe("calcite-tree", () => {
expect(selectEventSpy).toHaveReceivedEventTimes(3);
});

describe("has selected items in the selection event payload", () =>
it("contains current selection when selection=multi + input-enabled", async () => {
const page = await newE2EPage({
html: html` <calcite-tree selection-mode="multi" input-enabled>
<calcite-tree-item id="1">1</calcite-tree-item>
<calcite-tree-item id="2">2</calcite-tree-item>
</calcite-tree>`
});

const [item1, item2] = await page.findAll("calcite-tree-item");

type TestWindow = {
selectedIds: string[];
} & Window &
typeof globalThis;

await page.evaluateHandle(() =>
document.addEventListener("calciteTreeSelect", ({ detail }: CustomEvent) => {
(window as TestWindow).selectedIds = detail.selected.map((item) => item.id);
})
);

const getSelectedIds = async (): Promise<any> => page.evaluate(() => (window as TestWindow).selectedIds);

await item1.click();

expect(await getSelectedIds()).toEqual(["1"]);

await item2.click();

expect(await getSelectedIds()).toEqual(["1", "2"]);

await item2.click();

expect(await getSelectedIds()).toEqual(["1"]);

await item1.click();

expect(await getSelectedIds()).toEqual([]);
}));

it("emits once when the tree item checkbox label is clicked", async () => {
const page = await newE2EPage({
html: html`<calcite-tree input-enabled selection-mode="ancestors">
Expand Down