Skip to content

Commit 2e1a9fe

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

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
@@ -557,6 +557,9 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
557557
host: {
558558
'class': 'cdk-tree-node',
559559
'[attr.aria-expanded]': 'isExpanded',
560+
'[attr.aria-level]': 'level + 1',
561+
'[attr.aria-posinset]': '_getPositionInSet()',
562+
'[attr.aria-setsize]': '_getSetSize()',
560563
},
561564
})
562565
export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit {
@@ -624,14 +627,21 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
624627
return this._tree._getLevelAccessor()?.(this._data) ?? this._parentNodeAriaLevel;
625628
}
626629

630+
_getSetSize(): number {
631+
return 0;
632+
}
633+
634+
_getPositionInSet(): number {
635+
return 0;
636+
}
637+
627638
constructor(protected _elementRef: ElementRef<HTMLElement>, protected _tree: CdkTree<T, K>) {
628639
CdkTreeNode.mostRecentTreeNode = this as CdkTreeNode<T, K>;
629640
this.role = 'treeitem';
630641
}
631642

632643
ngOnInit(): void {
633644
this._parentNodeAriaLevel = getParentNodeAriaLevel(this._elementRef.nativeElement);
634-
this._elementRef.nativeElement.setAttribute('aria-level', `${this.level + 1}`);
635645
}
636646

637647
ngOnDestroy() {

0 commit comments

Comments
 (0)