From 92543c65c7efb91953044423d9b845c3b61c776b Mon Sep 17 00:00:00 2001 From: anveshmekala Date: Mon, 14 Aug 2023 14:32:35 -0500 Subject: [PATCH 1/3] fix(tree): selects all child items when selection-mode is set to ancestors --- packages/calcite-components/src/components/tree/tree.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/calcite-components/src/components/tree/tree.tsx b/packages/calcite-components/src/components/tree/tree.tsx index 77165d47654..5c9314ee205 100644 --- a/packages/calcite-components/src/components/tree/tree.tsx +++ b/packages/calcite-components/src/components/tree/tree.tsx @@ -336,7 +336,6 @@ export class Tree { ); const childItemsWithNoChildren = childItems.filter((child) => !child.hasChildren); const childItemsWithChildren = childItems.filter((child) => child.hasChildren); - const futureSelected = item.hasChildren ? !(item.selected || item.indeterminate) : !item.selected; @@ -357,7 +356,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(":scope > calcite-tree > calcite-tree-item") ); From 46e7f4c7b7b88e43f43eaf94d7eaab2fa80bf6fe Mon Sep 17 00:00:00 2001 From: anveshmekala Date: Mon, 14 Aug 2023 15:45:28 -0500 Subject: [PATCH 2/3] add test --- .../src/components/tree/tree.e2e.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/calcite-components/src/components/tree/tree.e2e.ts b/packages/calcite-components/src/components/tree/tree.e2e.ts index 10bfb8c06a6..4ed50470671 100644 --- a/packages/calcite-components/src/components/tree/tree.e2e.ts +++ b/packages/calcite-components/src/components/tree/tree.e2e.ts @@ -126,6 +126,11 @@ describe("calcite-tree", () => { Grandchild 2 + + + Great Grandchild + @@ -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"); @@ -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 @@ -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(); @@ -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(); @@ -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(); @@ -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", () => { From b205885d62c1404b361204b4058a7871b69249e6 Mon Sep 17 00:00:00 2001 From: anveshmekala Date: Mon, 14 Aug 2023 17:00:29 -0500 Subject: [PATCH 3/3] restore newlines --- packages/calcite-components/src/components/tree/tree.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/calcite-components/src/components/tree/tree.tsx b/packages/calcite-components/src/components/tree/tree.tsx index 5c9314ee205..a0b663743e4 100644 --- a/packages/calcite-components/src/components/tree/tree.tsx +++ b/packages/calcite-components/src/components/tree/tree.tsx @@ -336,6 +336,7 @@ export class Tree { ); const childItemsWithNoChildren = childItems.filter((child) => !child.hasChildren); const childItemsWithChildren = childItems.filter((child) => child.hasChildren); + const futureSelected = item.hasChildren ? !(item.selected || item.indeterminate) : !item.selected;