angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.39k stars 6.76k forks source link

bug(mat-tree): How to control a tree expansion state if treeControl is deprecated? #29856

Open ronlawrence3 opened 1 month ago

ronlawrence3 commented 1 month ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

mat-tree has [treeControl] (and many other related classes and parts) deprecated. How are we supposed to control the expansion state of the tree from our component if there is to no treeControl? Was this an oversight in documentation? even your own examples in the documentation use the deprecated features!

Reproduction

N/A

Expected Behavior

I expect deprecated features / componenets / classes to have a new replacement or documentation on HOW to use the new way of doing things that accounts for the deprecated feature.

Actual Behavior

In this case (CdkTree):

    /**
     * The tree controller
     *
     * @deprecated Use one of `levelAccessor` or `childrenAccessor` instead. To be removed in a
     * future version.
     * @breaking-change 21.0.0
     */
    treeControl?: TreeControl<T, K>;

levelAccessor and childrenAccessor have nothing to do with expansion state. Please tell us what we are supposed to use in place of treeControl!

Environment

ymombrun commented 1 month ago

I had the same feelings, after trying a few stuff, I realised that when you add #node=matNestedTreeNode on your mat-nested-tree-node tag, then you have access node.isExpanded in place of the treeControl.isExpanded(dataNode).

But indeed there is something to do with the documentation associated to this deprecation notice.

poirierlouis commented 3 weeks ago

As I was trying to migrate to, I found it through API documentation. You can use MatTree to expand/collapse/isExpanded with, for example:

@ViewChild(MatTree)
tree: MatTree

I agree though, documentation is not yet ready to guide us and migrate away from deprecated features. It looks like non-TreeControl implementation is not mature enough anyway for now.