-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(cdk/tree): fix level for nested tree nodes #20226
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
Conversation
a5f8a37
to
ffff172
Compare
src/cdk/tree/tree.ts
Outdated
@@ -128,7 +128,10 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest | |||
new BehaviorSubject<{start: number, end: number}>({start: 0, end: Number.MAX_VALUE}); | |||
|
|||
constructor(private _differs: IterableDiffers, | |||
private _changeDetectorRef: ChangeDetectorRef) {} | |||
private _changeDetectorRef: ChangeDetectorRef, | |||
private _elementRef: ElementRef<HTMLElement>) { |
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.
Changing the constructor signature for CdkTree
seems like it would be a breaking change since we do expect people will extend this class. Is there a way we can do this without changing the signature?
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.
The typical way we handle this is to make the new parameter optional and add a TODO
// @breaking-change 11.0.0 make this required
private _elementRef?: ElementRef<HTMLElement>
and then of course we need to handle the fact that the argument might be undefined
. In this case I'm not sure how we could handle it being undefined though, since we've switched to applying the class this way...
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.
maybe instead we could do individual host bindings?
@HostBinding('class.cdk-tree') _cdkTreeClass = true;
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.
Probably, I can't think of another way we could do it
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.
Solution:
Add the class on the host
property for CdkTree
and have both cdk-tree
and mat-tree
classes on MatTree
.
Justification:
- Cannot add the class as a
@HostBinding
as the class is not applied yet when the children nodes try to read the class off of it.- Moving the logic setting
aria-level
later causes further timing issues withMatTree
- Moving the logic setting
- Cannot directly add the class in the constructor as it is a breaking change (discussed above).
Added comment in the MatTree
class for clarification
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.
LGTM
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.
lgtm
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
…asses inheriting CdkTreeNode
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.
LGTM
Thanks for being so patient and thorough with this change. This uncovered a lot of subtle tricky bugs, but taking the time to work through them and fix them is definitely going to pay off for our users |
* fix(cdk/tree): fix level for flat and nested tree nodes * add test for material/tree * cache parent level instead of traversing DOM on ever level get * logging * set aria-level in ngOnInit, clean up * public api * change host binding to @HostBinding * use host:{} for mat tree and hostbinding for cdk tree * fix tslint comments, fix class inheritance for mat tree * clarify adding class directly to elementRef instead of on host property * minor fixes * fix isNodeElement method name/logic, guarantee boolean value * clean up duplicate @HostBinding and host:{} * replace isDevMode() * super life cycle hooks * public api update * comments explaining super life hook calls, add aria-expanded with setAttribute * set aria-expaded in ngDoCheck * remove duplicate input from MatTreeNode, add missing inputs:[] for classes inheriting CdkTreeNode * add super.ngDoCheck() * change isExpanded setter to private method * remove setting aria-expanded in constructor (cherry picked from commit f951bf4)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
aria-level
for nested nodeslevel
for nested nodeslevel
was always0
for nested nodes