Skip to content

CDK-Tree (FlatTree docs) - Collapsing doesn't collapse descendants #18040

@avrahamkam

Description

@avrahamkam

Reproduction

The docs: https://material.angular.io/cdk/tree/overview#flat-tree
https://stackblitz.com/angular/ggqypydxrvv?file=src%2Fapp%2Fcdk-tree-flat-example.ts

(This issue doesn't effect MatTree).

Steps to reproduce:

  1. Expand Vegetables
  2. Expand Orange (to see Pumpkin and Carrots)
  3. Collapse Vegetables

This is the expanded view:
Screen Shot 2019-12-24 at 11 48 56 AM

Expected Behavior

Pumpkin and Carrots will be hidden

Actual Behavior

Orange is hidden but Pumpkin and Carrots are visible
Screen Shot 2019-12-24 at 11 49 02 AM

Environment

  • Angular: ^8.3.8,
  • Material: ~8.2.2
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Mac

Update

It seems that at the moment that treeControl.toggle is being called for both expand and collapse (because the cdkTreeNodeToggle is being used). Ideally, it should be using the treeControl.collapseDescendants method for collapse, and the treeControl.expand method for expand.

Stackblitz with proposed fix for the example in the docs:
https://stackblitz.com/edit/angular-d8rm6r?embed=1&file=src/app/cdk-tree-flat-example.ts

I've intentionally made use of the treeControl class instead of directly updating the node.isExpanded attribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/treedocsThis issue is related to documentationgood first issueThis issue is a good place to start for first time contributors to the projecthelp wantedThe team would appreciate a PR from the community to address this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions