Skip to content

Commit 6e9b282

Browse files
committed
fix(cdk/tree): remove TODOs and fix isExpanded
1 parent f873b4f commit 6e9b282

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/cdk/tree/tree.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
168168
end: Number.MAX_VALUE,
169169
});
170170

171-
// TODO(cassc): will be used in a future PR
172-
// tslint:disable-next-line:no-unused-variable
171+
/** Keep track of which nodes are expanded. */
173172
private _expansionModel?: SelectionModel<K>;
174173
/** Maintain a synchronous cache of the currently known data nodes. */
175-
// TODO(cassc): will be used in a future PR
176-
// tslint:disable-next-line:no-unused-variable
177174
private _dataNodes?: readonly T[];
178175

179176
constructor(private _differs: IterableDiffers, private _changeDetectorRef: ChangeDetectorRef) {}
@@ -583,7 +580,14 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
583580

584581
@Input()
585582
get isExpanded(): boolean {
586-
return !!this._tree.treeControl?.isExpanded(this._data);
583+
return !!this._tree.isExpanded(this._data);
584+
}
585+
set isExpanded(isExpanded: boolean) {
586+
if (isExpanded) {
587+
this._tree.expand(this.data);
588+
} else {
589+
this._tree.collapse(this.data);
590+
}
587591
}
588592

589593
/**

tools/public_api_guard/cdk/tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
145145
isExpandable: boolean;
146146
// (undocumented)
147147
get isExpanded(): boolean;
148+
set isExpanded(isExpanded: boolean);
148149
// (undocumented)
149150
get level(): number;
150151
static mostRecentTreeNode: CdkTreeNode<any> | null;

0 commit comments

Comments
 (0)