From 7c6e4727159f733f5e47aea0f1a27b409431a844 Mon Sep 17 00:00:00 2001 From: "nantawat.poothong" Date: Tue, 26 Sep 2023 16:42:57 +0700 Subject: [PATCH] fix(tree): stateless set expand/collapse label only single selection --- packages/elements/src/tree/__test__/tree.test.js | 10 +++++++--- packages/elements/src/tree/elements/tree.ts | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/elements/src/tree/__test__/tree.test.js b/packages/elements/src/tree/__test__/tree.test.js index 7d51e7a374..83df5d9e84 100644 --- a/packages/elements/src/tree/__test__/tree.test.js +++ b/packages/elements/src/tree/__test__/tree.test.js @@ -533,7 +533,7 @@ describe('tree/Tree', function () { }); describe('Stateless Mode', function () { - it('Should expand or collapse when tapping on parent', async function () { + it('Should expand/collapse when tapping on single mode parent', async function () { const el = await fixture(''); el.data = nestedData; await elementUpdated(el); @@ -547,14 +547,18 @@ describe('tree/Tree', function () { expect(el.children[0].expanded).to.be.true; }); - it('Should not expand or collapse when tapping on multiple mode parent', async function () { + it('Should not expand/collapse when tapping on multiple mode parent', async function () { const el = await fixture(''); el.data = nestedData; await elementUpdated(el); el.children[0].click(); await elementUpdated(el); - expect(el.children[0].expanded).to.be.false; + expect(el.children[0].expanded).to.be.true; + + el.children[0].click(); + await elementUpdated(el); + expect(el.children[0].expanded).to.be.true; }); it('Should not select value when tapping on multiple mode parent', async function () { diff --git a/packages/elements/src/tree/elements/tree.ts b/packages/elements/src/tree/elements/tree.ts index 7b263d4276..c0b729ee71 100644 --- a/packages/elements/src/tree/elements/tree.ts +++ b/packages/elements/src/tree/elements/tree.ts @@ -117,7 +117,8 @@ export class Tree extends List { public override selectItem(item: T): boolean { // Stateless tree if (this.stateless) { - if (this.manager.isItemParent(item)) { + // Single selection - expand/collapse group (parent) + if (!this.multiple && this.manager.isItemParent(item)) { this.toggleExpandedState(item); } return false;