Skip to content

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

Merged
merged 22 commits into from
Sep 9, 2020

Conversation

annieyw
Copy link
Contributor

@annieyw annieyw commented Aug 6, 2020

  • set aria-level for nested nodes
  • fix level for nested nodes
    • previously level was always 0 for nested nodes

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 6, 2020
@annieyw annieyw requested review from jelbourn and mmalerba August 6, 2020 22:49
@annieyw annieyw marked this pull request as ready for review August 7, 2020 20:24
@annieyw annieyw requested a review from andrewseguin as a code owner August 7, 2020 20:24
@mmalerba mmalerba changed the title fix(cdk/tree): fix level nested tree nodes fix(cdk/tree): fix level for nested tree nodes Aug 7, 2020
@@ -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>) {
Copy link
Member

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?

Copy link
Contributor

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...

Copy link
Contributor

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;

Copy link
Member

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

Copy link
Contributor Author

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 with MatTree
  • Cannot directly add the class in the constructor as it is a breaking change (discussed above).

Added comment in the MatTree class for clarification

@mmalerba mmalerba added G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround labels Aug 10, 2020
@annieyw annieyw requested review from mmalerba and jelbourn August 10, 2020 22:08
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added the target: patch This PR is targeted for the next patch release label Aug 11, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@annieyw annieyw added the action: merge The PR is ready for merge by the caretaker label Aug 13, 2020
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@annieyw annieyw removed request for a team, devversion and andrewseguin August 31, 2020 17:34
@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Aug 31, 2020
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba
Copy link
Contributor

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

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Aug 31, 2020
@andrewseguin andrewseguin merged commit f951bf4 into angular:master Sep 9, 2020
andrewseguin pushed a commit that referenced this pull request Sep 9, 2020
* 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)
@annieyw annieyw deleted the dom-parent branch September 9, 2020 17:11
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants