Skip to content

Commit bdbd829

Browse files
committed
fix(cdk/tree): add aria attributes for the flat nodes
1 parent c4b06b7 commit bdbd829

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/cdk/tree/tree.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,9 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
717717
host: {
718718
'class': 'cdk-tree-node',
719719
'[attr.aria-expanded]': 'isExpanded',
720+
'[attr.aria-level]': 'level + 1',
721+
'[attr.aria-posinset]': '_getPositionInSet()',
722+
'[attr.aria-setsize]': '_getSetSize()',
720723
},
721724
})
722725
export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit {
@@ -784,14 +787,21 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
784787
return this._tree._getLevel(this._data) ?? this._parentNodeAriaLevel;
785788
}
786789

790+
_getSetSize(): number {
791+
return 0;
792+
}
793+
794+
_getPositionInSet(): number {
795+
return 0;
796+
}
797+
787798
constructor(protected _elementRef: ElementRef<HTMLElement>, protected _tree: CdkTree<T, K>) {
788799
CdkTreeNode.mostRecentTreeNode = this as CdkTreeNode<T, K>;
789800
this.role = 'treeitem';
790801
}
791802

792803
ngOnInit(): void {
793804
this._parentNodeAriaLevel = getParentNodeAriaLevel(this._elementRef.nativeElement);
794-
this._elementRef.nativeElement.setAttribute('aria-level', `${this.level + 1}`);
795805
this._tree._registerNode(this);
796806
}
797807

0 commit comments

Comments
 (0)