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): selects all child items when selection-mode is set to ancestors #7518

Merged
Merged
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
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
@@ -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>
@@ -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", () => {
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/tree/tree.tsx
Original file line number Diff line number Diff line change
@@ -357,7 +357,7 @@ export class Tree {
item.indeterminate = selected.length > 0 && unselected.length > 0;
}

childItemsWithChildren.forEach((el) => {
childItemsWithChildren.reverse().forEach((el) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue at the moment, but this is also modifying the source array. Might not be clear this has happened if you reference the variable afterwards. Calling slice before reverse should mitigate this.

const directChildItems = Array.from(
el.querySelectorAll<HTMLCalciteTreeItemElement>(":scope > calcite-tree > calcite-tree-item")
);