Skip to content

Commit

Permalink
fix(tree): selects all child items when selection-mode is set to ance…
Browse files Browse the repository at this point in the history
…stors (#7518)

**Related Issue:** #7104 

## Summary

Selects all the child `calcite-tree-item` elements when the root element
is selected with `selection-mode="ancestors"`
  • Loading branch information
anveshmekala committed Aug 14, 2023
1 parent c1584a1 commit f1eef84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/calcite-components/src/components/tree/tree.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ describe("calcite-tree", () => {
</calcite-tree-item>
<calcite-tree-item id="grandchild-two">
<span>Grandchild 2</span>
<calcite-tree slot="children">
<calcite-tree-item id="greatgrandchild">
<span>Great Grandchild</span>
</calcite-tree-item></calcite-tree
>
</calcite-tree-item>
</calcite-tree>
</calcite-tree-item>
Expand All @@ -140,6 +145,7 @@ describe("calcite-tree", () => {
const childTwo = await page.find("#child-two");
const grandchildOne = await page.find("#grandchild-one");
const grandchildTwo = await page.find("#grandchild-two");
const greatgrandchild = await page.find("#greatgrandchild");

expect(one).not.toHaveAttribute("indeterminate");
expect(one).not.toHaveAttribute("selected");
Expand All @@ -149,6 +155,7 @@ describe("calcite-tree", () => {
expect(childOne).not.toHaveAttribute("selected");
expect(grandchildOne).not.toHaveAttribute("selected");
expect(grandchildTwo).not.toHaveAttribute("selected");
expect(greatgrandchild).not.toHaveAttribute("selected");

// Puppeteer's element click will happen in the center of a component,
// so we call the method to ensure it happens on the component of interest
Expand All @@ -163,6 +170,7 @@ describe("calcite-tree", () => {
expect(childTwo).toHaveAttribute("selected");
expect(grandchildOne).toHaveAttribute("selected");
expect(grandchildTwo).toHaveAttribute("selected");
expect(greatgrandchild).toHaveAttribute("selected");

await childOne.callMethod("click");
await page.waitForChanges();
Expand All @@ -175,6 +183,7 @@ describe("calcite-tree", () => {
expect(childTwo).toHaveAttribute("selected");
expect(grandchildOne).not.toHaveAttribute("selected");
expect(grandchildTwo).not.toHaveAttribute("selected");
expect(greatgrandchild).not.toHaveAttribute("selected");

grandchildTwo.setProperty("disabled", true);
await page.waitForChanges();
Expand All @@ -189,6 +198,7 @@ describe("calcite-tree", () => {
expect(childTwo).not.toHaveAttribute("selected");
expect(grandchildOne).not.toHaveAttribute("selected");
expect(grandchildTwo).not.toHaveAttribute("selected");
expect(greatgrandchild).not.toHaveAttribute("selected");

grandchildTwo.setProperty("disabled", false);
await page.waitForChanges();
Expand All @@ -202,6 +212,7 @@ describe("calcite-tree", () => {
expect(childTwo).toHaveAttribute("selected");
expect(grandchildOne).toHaveAttribute("selected");
expect(grandchildTwo).toHaveAttribute("selected");
expect(greatgrandchild).toHaveAttribute("selected");
});

describe("item selection", () => {
Expand Down
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 @@ -357,7 +357,7 @@ export class Tree {
item.indeterminate = selected.length > 0 && unselected.length > 0;
}

childItemsWithChildren.forEach((el) => {
childItemsWithChildren.reverse().forEach((el) => {
const directChildItems = Array.from(
el.querySelectorAll<HTMLCalciteTreeItemElement>(":scope > calcite-tree > calcite-tree-item")
);
Expand Down

0 comments on commit f1eef84

Please sign in to comment.