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

uncheckAllItems method not update checked state of parent node #526

Merged
merged 8 commits into from
Nov 18, 2022
44 changes: 44 additions & 0 deletions packages/elements/src/tree/__test__/tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,50 @@ describe('tree/Tree', () => {
expect(el.values).to.deep.equal(['1.1', '1.2', '4']);
});

it('Uncheck all items correctly with deep nested data', async () => {
const el = await fixture('<ef-tree multiple></ef-tree>');
el.data = deepNestedData;
await elementUpdated(el);
el.uncheckAll();
el.expandAll();
await elementUpdated(el);
const item = el.children[3];
const itemChild = el.children[4];
itemChild.click();
await elementUpdated(el);
el.uncheckAll();
await elementUpdated(el);
expect(item.checkedState).to.equal(0);
el.uncheckAll();
await elementUpdated(el);
el.values = ['1.3.1.1'];
await elementUpdated(el);
el.uncheckAll();
await elementUpdated(el);
expect(item.checkedState).to.equal(0);
expect(itemChild.checkedState).to.equal(0);
});

it('check/uncheck all items correctly in no-relation with deep nested data', async () => {
const el = await fixture('<ef-tree multiple no-relation></ef-tree>');
el.data = deepNestedData;
await elementUpdated(el);
el.uncheckAll();
el.expandAll();
await elementUpdated(el);
const item = el.children[3];
const itemChild = el.children[4];
itemChild.click();
await elementUpdated(el);
el.uncheckAll();
await elementUpdated(el);
expect(item.checkedState).to.equal(0);
el.checkAll();
await elementUpdated(el);
expect(item.checkedState).to.equal(1);
expect(itemChild.checkedState).to.equal(1);
});

it('Can set values programmatically', async () => {
const el = await fixture('<ef-tree multiple></ef-tree>');
el.data = nestedData;
Expand Down
5 changes: 4 additions & 1 deletion packages/elements/src/tree/managers/tree-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export class TreeManager<T extends TreeDataItem> {
this.forceUpdateOnPath(item);
this.getItemDescendants(item).forEach(descendant => this._uncheckItem(descendant, false));
}
this.updateItem(item);
return true;
}
return false;
Expand Down Expand Up @@ -437,6 +438,8 @@ export class TreeManager<T extends TreeDataItem> {
* @returns {void}
*/
public uncheckAllItems (): void {
this.editableItems.forEach(item => this.uncheckItem(item));
// uncheck items from top levels when manage relationships to avoid redundant re-renders
const items = this.manageRelationships ? this.composer.queryItems(() => true, 0) : this.checkedItems;
Sarin-Udompanish marked this conversation as resolved.
Show resolved Hide resolved
items.forEach(item => this.uncheckItem(item));
}
}