components icon indicating copy to clipboard operation
components copied to clipboard

bug(MatTree): expandAll() only expand the first level

Open robmv opened this issue 4 months ago • 0 comments

Is this a regression?

  • [x] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

17.x

Description

The method expandAll() of MatTree expands only the first level of a deeply nested tree. On deprecated MatTreeControl, the same method was able to expand the entire tree without problems.

Note: the deprecated control had an advantage that the expansion state could be manipulated before even the view was initialized, but that is another topic.

WORKAROUND:

this.dataSource.forEach(node => this.tree.expandDescendants(node));

Reproduction

StackBlitz link:

  • Flat nodes: https://stackblitz.com/edit/rk3djh
  • Nested nodes: https://stackblitz.com/edit/mv8yub

Steps to reproduce:

  1. Open the demos.
  2. The tree is partially expanded
  3. Edit the demo and enable the workaround on the ngAfterViewInit callback.
  4. The tree is now fully expanded.

Expected Behavior

MatTree's expandAll() should expand all nodes.

Actual Behavior

Only the first level nodes are expanded.

Environment

  • Angular: 18.2.8
  • CDK/Material: 18.2.8
  • Browser(s): Firefox, Chromium
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux (Fedora)

robmv avatar Oct 11 '24 14:10 robmv