Skip to content

fix(tree): fix nested node cannot expand/collapse multiple times #10671

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

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cdk/tree/nested-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ export class CdkNestedTreeNode<T> extends CdkTreeNode<T> implements AfterContent
if (this.nodeOutlet.length && this._children) {
const viewContainer = this.nodeOutlet.first.viewContainer;
this._tree.renderNodeChanges(this._children, this._dataDiffer, viewContainer);
} else {
// Reset the data differ if there's no children nodes displayed
this._dataDiffer.diff([]);
}
}

/** Clear the children dataNodes. */
protected _clear(): void {
if (this.nodeOutlet && this.nodeOutlet.first) {
this.nodeOutlet.first.viewContainer.clear();
this._dataDiffer.diff([]);
}
}
}
13 changes: 12 additions & 1 deletion src/cdk/tree/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ describe('CdkTree', () => {
fixture.detectChanges();
});

it('should expand/collapse the node', () => {
it('should expand/collapse the node multiple times', () => {
component.toggleRecursively = false;
let data = dataSource.data;
const child = dataSource.addChild(data[1], false);
Expand Down Expand Up @@ -477,6 +477,17 @@ describe('CdkTree', () => {
[`topping_3 - cheese_3 + base_3`]);
expect(component.treeControl.expansionModel.selected.length)
.toBe(0, `Expect node collapsed`);

(getNodes(treeElement)[1] as HTMLElement).click();
fixture.detectChanges();

expect(component.treeControl.expansionModel.selected.length)
.toBe(1, `Expect node expanded`);
expectNestedTreeToMatch(treeElement,
[`topping_1 - cheese_1 + base_1`],
[`topping_2 - cheese_2 + base_2`],
[_, `topping_4 - cheese_4 + base_4`],
[`topping_3 - cheese_3 + base_3`]);
});

it('should expand/collapse the node recursively', () => {
Expand Down