Skip to content

Commit a5b0d1a

Browse files
committed
fix(material/tree): refactor isLeafNode function
refactored isLeafNode function to make more sense Fixes #21922
1 parent df9f5be commit a5b0d1a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/cdk/tree/tree.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
321321
exportAs: 'cdkTreeNode',
322322
host: {
323323
'class': 'cdk-tree-node',
324-
'[attr.aria-expanded]': 'isLeafNode',
324+
'[attr.aria-expanded]': 'isLeafNode ? null : isExpanded',
325325
},
326326
standalone: true,
327327
})
@@ -368,23 +368,27 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
368368
}
369369
protected _data: T;
370370

371-
/* If leaf node, do not assign aria-expanded attribute */
372-
get isLeafNode(): boolean | null {
371+
/* If leaf node, return true to not assign aria-expanded attribute */
372+
get isLeafNode(): boolean {
373373
// If flat tree node data returns false for expandable property, it's a leaf node
374374
if (
375375
this._tree.treeControl.isExpandable !== undefined &&
376376
!this._tree.treeControl.isExpandable(this._data)
377377
) {
378-
return null;
378+
return true;
379379

380380
// If nested tree node data returns 0 descendants, it's a leaf node
381381
} else if (
382382
this._tree.treeControl.isExpandable === undefined &&
383383
this._tree.treeControl.getDescendants(this._data).length === 0
384384
) {
385-
return null;
385+
return true;
386386
}
387387

388+
return false;
389+
}
390+
391+
get isExpanded(): boolean {
388392
return this._tree.treeControl.isExpanded(this._data);
389393
}
390394

0 commit comments

Comments
 (0)