Skip to content

Commit

Permalink
always set role to treeitem
Browse files Browse the repository at this point in the history
  • Loading branch information
annieyw committed Jul 30, 2020
1 parent de439a5 commit 018dd3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
27 changes: 11 additions & 16 deletions src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy {
}

/**
* The role of the node should be 'group' if it's an internal node,
* and 'treeitem' if it's a leaf node.
* The role of the node should always be 'treeitem'.
*/
@Input() role: 'treeitem' | 'group' = 'treeitem';

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

protected _setRoleFromData(): void {
if (this._tree.treeControl.isExpandable) {
this.role = this._tree.treeControl.isExpandable(this._data) ? 'group' : 'treeitem';
} else {
if (!this._tree.treeControl.getChildren) {
throw getTreeControlFunctionsMissingError();
}
const childrenNodes = this._tree.treeControl.getChildren(this._data);
if (Array.isArray(childrenNodes)) {
this._setRoleFromChildren(childrenNodes as T[]);
} else if (isObservable(childrenNodes)) {
childrenNodes.pipe(takeUntil(this._destroyed))
.subscribe(children => this._setRoleFromChildren(children));
}
if (this._tree.treeControl.isExpandable && !this._tree.treeControl.getChildren) {
throw getTreeControlFunctionsMissingError();
}
const childrenNodes = this._tree.treeControl.getChildren(this._data);
if (Array.isArray(childrenNodes)) {
this._setRoleFromChildren(childrenNodes as T[]);
} else if (isObservable(childrenNodes)) {
childrenNodes.pipe(takeUntil(this._destroyed))
.subscribe(children => this._setRoleFromChildren(children));
}
}

protected _setRoleFromChildren(children: T[]) {
this.role = children && children.length ? 'group' : 'treeitem';
this.role = 'treeitem';
}
}
4 changes: 2 additions & 2 deletions src/material/tree/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const _MatTreeNodeMixinBase: HasTabIndexCtor & CanDisableCtor & typeof CdkTreeNo
host: {
'[attr.aria-expanded]': 'isExpanded',
'[attr.aria-level]': 'level + 1',
'[attr.role]': `'treeitem'`,
'[attr.role]': 'role',
'class': 'mat-tree-node'
},
providers: [{provide: CdkTreeNode, useExisting: MatTreeNode}]
Expand Down Expand Up @@ -88,7 +88,7 @@ export class MatTreeNodeDef<T> extends CdkTreeNodeDef<T> {
exportAs: 'matNestedTreeNode',
host: {
'[attr.aria-expanded]': 'isExpanded',
'[attr.role]': `'treeitem'`,
'[attr.role]': 'role',
'class': 'mat-nested-tree-node',
},
providers: [
Expand Down

0 comments on commit 018dd3b

Please sign in to comment.