-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(material/tree): Do not add aria-expanded to leaf nodes #18032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32808a6
11ae3ce
b58d9bb
de2a626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,8 +290,8 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest | |
selector: 'cdk-tree-node', | ||
exportAs: 'cdkTreeNode', | ||
host: { | ||
'[attr.aria-expanded]': 'isExpanded', | ||
'[attr.aria-level]': 'role === "treeitem" ? level : null', | ||
'[attr.aria-expanded]': 'expandable ? isExpanded : null', | ||
'[attr.aria-level]': 'level', | ||
'[attr.role]': 'role', | ||
'class': 'cdk-tree-node', | ||
}, | ||
|
@@ -334,6 +334,8 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy { | |
*/ | ||
@Input() role: 'treeitem' | 'group' = 'treeitem'; | ||
|
||
expandable = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you prefix this member with an underscore to signal that it's not part of the public API? |
||
|
||
constructor(protected _elementRef: ElementRef<HTMLElement>, | ||
protected _tree: CdkTree<T>) { | ||
CdkTreeNode.mostRecentTreeNode = this as CdkTreeNode<T>; | ||
|
@@ -358,6 +360,7 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy { | |
|
||
protected _setRoleFromData(): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 1, I would rename this method to For 2, I think it's the same issue as #17818 |
||
if (this._tree.treeControl.isExpandable) { | ||
this.expandable = this._tree.treeControl.isExpandable(this._data); | ||
this.role = this._tree.treeControl.isExpandable(this._data) ? 'group' : 'treeitem'; | ||
} else { | ||
if (!this._tree.treeControl.getChildren) { | ||
|
@@ -374,6 +377,7 @@ export class CdkTreeNode<T> implements FocusableOption, OnDestroy { | |
} | ||
|
||
protected _setRoleFromChildren(children: T[]) { | ||
this.expandable = children && children.length > 0; | ||
this.role = children && children.length ? 'group' : 'treeitem'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this
addChildren
flag as a way to optionally add children to the data source before the tree is rendered, because aria attribute changes were not reflected in the DOM otherwise. Ideally I would remove this. See other comment -- I need to find a way to make the parent node update its data when a child is added to it. I think this might just be a test change, but I could use another pair of eyes on this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably the same issue as I commented on in #17818