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): allow deselection in single selectionMode #9363

Merged
merged 20 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
68de2ce
fix(tree): allow selection/deselection in single mode
josercarcamo May 17, 2024
4468431
Merge branch 'main' into josercarcamo/7900-tree-single-select
josercarcamo May 17, 2024
8bd48ed
Changed test to reflect change in logic
josercarcamo May 20, 2024
b5bb18f
Merge branch 'josercarcamo/7900-tree-single-select' of github.com:Esr…
josercarcamo May 20, 2024
23a258a
Changed test to reflect change in logic
josercarcamo May 20, 2024
9034b68
Changed test to reflect change in logic
josercarcamo May 20, 2024
200c791
Changed test to reflect change in logic
josercarcamo May 20, 2024
450da7e
Changed test to reflect change in logic
josercarcamo May 21, 2024
4ce7028
Changed test to reflect change in logic
josercarcamo May 22, 2024
7234981
Changed test to reflect change in logic
josercarcamo May 22, 2024
0a927e8
Refactored line of code per code review
josercarcamo May 22, 2024
abb4039
Merge branch 'main' into josercarcamo/7900-tree-single-select
josercarcamo May 22, 2024
0cd9db2
Reverted line of code because not logically equivalent
josercarcamo May 22, 2024
c799667
Rewrote suggested line
josercarcamo May 22, 2024
03a1451
Merge branch 'josercarcamo/7900-tree-single-select' of github.com:Esr…
josercarcamo May 22, 2024
246ad2c
Uncommented test case
josercarcamo May 22, 2024
fac0a89
Uncommented test case
josercarcamo May 22, 2024
b307e44
Uncommented test case
josercarcamo May 22, 2024
c16ec3b
Uncommented test case
josercarcamo May 22, 2024
70b16df
Uncommented test case
josercarcamo May 22, 2024
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
46 changes: 39 additions & 7 deletions packages/calcite-components/src/components/tree/tree.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,11 @@ describe("calcite-tree", () => {
Child 2

<calcite-tree slot="children">
<calcite-tree-item id="${expandableItemChildId}">Grandchild 1</calcite-tree-item>
<calcite-tree-item>Grandchild 1</calcite-tree-item>

<calcite-tree-item>Grandchild 2</calcite-tree-item>

<calcite-tree-item>
<calcite-tree-item id="${expandableItemChildId}">
Grandchild 3
<calcite-tree slot="children">
<calcite-tree-item>Great-Grandchild 1</calcite-tree-item>
Expand Down Expand Up @@ -1292,10 +1292,11 @@ describe("calcite-tree", () => {
? 0
: selectionMode === "ancestors" && !childToggleTraversesParent
? 7
: !childToggleTraversesParent &&
(selectionMode === "multiple" || selectionMode === "single" || selectionMode === "single-persist")
: selectionMode === "multiple" || selectionMode === "single" || selectionMode === "single-persist"
? 0
: 1,
: selectionMode === "children" || selectionMode === "multichildren"
? 1
: 4,
);

await selectItemChild(page, expandableChildItem);
Expand All @@ -1307,14 +1308,45 @@ describe("calcite-tree", () => {
selectionMode === "none"
? 0
: !childToggleTraversesParent && selectionMode === "multiple"
? 1
: canDeselect.child
? 0
: canDeselect.child || selectionMode === "single" || selectionMode === "single-persist"
? 0
: 1,
);
});
},
);
}

it("selects/deselects in single selection", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-tree selection-mode="single">
<calcite-tree-item id="child1">Child 1</calcite-tree-item>
<calcite-tree-item id="sub1">
Child 2
<calcite-tree slot="children">
<calcite-tree-item id="gc1">Grandchild 1</calcite-tree-item>
<calcite-tree-item>Grandchild 2</calcite-tree-item>
</calcite-tree>
</calcite-tree-item>
</calcite-tree>
`);
const tree = await page.find("calcite-tree");
expect(await tree.getProperty("selectedItems")).toHaveLength(0);
const child1 = await page.find("#child1");
await directItemClick(page, child1);
expect(await tree.getProperty("selectedItems")).toHaveLength(1);
await directItemClick(page, child1);
expect(await tree.getProperty("selectedItems")).toHaveLength(0);
const sub1 = await page.find("#sub1");
await directItemClick(page, sub1);
expect(await tree.getProperty("selectedItems")).toHaveLength(0);
const gc1 = await page.find("#gc1");
await directItemClick(page, gc1);
expect(await tree.getProperty("selectedItems")).toHaveLength(1);
await directItemClick(page, gc1);
expect(await tree.getProperty("selectedItems")).toHaveLength(0);
});
});
});
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/tree/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class Tree {
} else if (!isNoneSelectionMode) {
targetItems.forEach((treeItem) => {
if (!treeItem.disabled) {
treeItem.selected = true;
treeItem.selected = this.selectionMode !== "single" || !treeItem.selected;
}
});
}
Expand Down
Loading