Skip to content

Commit

Permalink
fix(tree): parent label can't expand/collapse in stateless mode (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nantawat-Poothong authored Sep 28, 2023
1 parent 5b86a2a commit 7151558
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/elements/src/tree/__test__/tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,46 @@ describe('tree/Tree', function () {
});
});

describe('Stateless Mode', 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);

el.children[0].click();
await elementUpdated(el);
expect(el.children[0].expanded).to.be.false;

el.children[0].click();
await elementUpdated(el);
expect(el.children[0].expanded).to.be.true;
});

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.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 () {
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.values).to.deep.equal(['1.2'], 'should have only 1.2 as default seleted value');
});
});

describe('Filter Tests', function () {
it('Text filter applied, query attribute - multi level', async function () {
const el = await fixture('<ef-tree query="-3" ></ef-tree>');
Expand Down
4 changes: 4 additions & 0 deletions packages/elements/src/tree/elements/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export class Tree<T extends TreeDataItem = TreeDataItem> extends List<T> {
public override selectItem(item: T): boolean {
// Stateless tree
if (this.stateless) {
// Single selection - expand/collapse group (parent)
if (!this.multiple && this.manager.isItemParent(item)) {
this.toggleExpandedState(item);
}
return false;
}
// Multiple selection
Expand Down

0 comments on commit 7151558

Please sign in to comment.