Skip to content

Commit 018dd3b

Browse files
committed
always set role to treeitem
1 parent de439a5 commit 018dd3b

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/cdk/tree/tree.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy {
337337
}
338338

339339
/**
340-
* The role of the node should be 'group' if it's an internal node,
341-
* and 'treeitem' if it's a leaf node.
340+
* The role of the node should always be 'treeitem'.
342341
*/
343342
@Input() role: 'treeitem' | 'group' = 'treeitem';
344343

@@ -365,23 +364,19 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy {
365364
}
366365

367366
protected _setRoleFromData(): void {
368-
if (this._tree.treeControl.isExpandable) {
369-
this.role = this._tree.treeControl.isExpandable(this._data) ? 'group' : 'treeitem';
370-
} else {
371-
if (!this._tree.treeControl.getChildren) {
372-
throw getTreeControlFunctionsMissingError();
373-
}
374-
const childrenNodes = this._tree.treeControl.getChildren(this._data);
375-
if (Array.isArray(childrenNodes)) {
376-
this._setRoleFromChildren(childrenNodes as T[]);
377-
} else if (isObservable(childrenNodes)) {
378-
childrenNodes.pipe(takeUntil(this._destroyed))
379-
.subscribe(children => this._setRoleFromChildren(children));
380-
}
367+
if (this._tree.treeControl.isExpandable && !this._tree.treeControl.getChildren) {
368+
throw getTreeControlFunctionsMissingError();
369+
}
370+
const childrenNodes = this._tree.treeControl.getChildren(this._data);
371+
if (Array.isArray(childrenNodes)) {
372+
this._setRoleFromChildren(childrenNodes as T[]);
373+
} else if (isObservable(childrenNodes)) {
374+
childrenNodes.pipe(takeUntil(this._destroyed))
375+
.subscribe(children => this._setRoleFromChildren(children));
381376
}
382377
}
383378

384379
protected _setRoleFromChildren(children: T[]) {
385-
this.role = children && children.length ? 'group' : 'treeitem';
380+
this.role = 'treeitem';
386381
}
387382
}

src/material/tree/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const _MatTreeNodeMixinBase: HasTabIndexCtor & CanDisableCtor & typeof CdkTreeNo
4545
host: {
4646
'[attr.aria-expanded]': 'isExpanded',
4747
'[attr.aria-level]': 'level + 1',
48-
'[attr.role]': `'treeitem'`,
48+
'[attr.role]': 'role',
4949
'class': 'mat-tree-node'
5050
},
5151
providers: [{provide: CdkTreeNode, useExisting: MatTreeNode}]
@@ -88,7 +88,7 @@ export class MatTreeNodeDef<T> extends CdkTreeNodeDef<T> {
8888
exportAs: 'matNestedTreeNode',
8989
host: {
9090
'[attr.aria-expanded]': 'isExpanded',
91-
'[attr.role]': `'treeitem'`,
91+
'[attr.role]': 'role',
9292
'class': 'mat-nested-tree-node',
9393
},
9494
providers: [

0 commit comments

Comments
 (0)