Skip to content

Commit

Permalink
fix(tree): tree query selection issues (#364)
Browse files Browse the repository at this point in the history
* fix(tree): tree query selection issues

* chore(tree): update test desciption
  • Loading branch information
Nantawat-Poothong authored Jun 17, 2022
1 parent d2351e5 commit cf1c072
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
43 changes: 43 additions & 0 deletions packages/elements/src/tree/__test__/tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,49 @@ describe('tree/Tree', () => {
descendants.forEach(item => expect(el.manager.isItemHidden(item)).to.equal(false, 'Descendants of matched items must be included'));
});

it('Should be able to select value after filter is applied', async () => {
const el = await fixture('<ef-tree></ef-tree>');
el.data = flatData;
await elementUpdated(el);

el.children[0].click();
await elementUpdated(el);

el.query = 'Item 4';
await elementUpdated(el);

el.children[0].click();
await elementUpdated(el);

expect(el.value).to.equal('4', 'Value should be update when selecting a new item on filter applied.');
});

it('Text filter applied, check/uncheck item and switch between single and multiple selection mode', async () => {
const el = await fixture('<ef-tree></ef-tree>');
el.data = flatData;
await elementUpdated(el);

el.children[0].click();
await elementUpdated(el);

el.query = 'Item 4';
await elementUpdated(el);

el.multiple = true
await elementUpdated(el);

el.uncheckAll();
await elementUpdated(el);
expect(el.value).to.equal('1', 'hidden selected item in multiple mode shouldn\'t unchecked');

el.multiple = false
await elementUpdated(el);

el.children[0].click();
await elementUpdated(el);
expect(el.value).to.equal('4', 'Value should be update when selecting a new item on filter applied.');

});
});
});

13 changes: 12 additions & 1 deletion packages/elements/src/tree/elements/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,24 @@ export class Tree<T extends TreeDataItem = TreeDataItem> extends List<T> {
// Single selection - check item
if (this.manager.checkItem(item)) {
this.manager.checkedItems.forEach(checkedItem => {
checkedItem !== item && this.manager.uncheckItem(checkedItem);
checkedItem !== item && this.forceUncheckItem(checkedItem);
});
return true;
}
return false;
}

/**
* Force uncheck item when item is locked
* @param item Original data item
* @returns {void}
*/
protected forceUncheckItem (item: T): void {
const result = this.composer.unlockItem(item);
this.manager.uncheckItem(item);
result && this.composer.lockItem(item);
}

/**
* Dispatches an event, detailing which item has recently changed it's expanded state.
* @param item Data item of which the expanded property changed
Expand Down

0 comments on commit cf1c072

Please sign in to comment.