Skip to content

Commit

Permalink
fix(tree): stateless set expand/collapse label only single selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nantawat-Poothong committed Sep 26, 2023
1 parent ae909c8 commit 7c6e472
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/elements/src/tree/__test__/tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ef-tree stateless></ef-tree>');
el.data = nestedData;
await elementUpdated(el);
Expand All @@ -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('<ef-tree multiple stateless></ef-tree>');
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 () {
Expand Down
3 changes: 2 additions & 1 deletion packages/elements/src/tree/elements/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export class Tree<T extends TreeDataItem = TreeDataItem> extends List<T> {
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;
Expand Down

0 comments on commit 7c6e472

Please sign in to comment.