angular / angular/components

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

Offen
#30,445 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: cdk/tree P3
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

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

Reopen Issue #29865. [CDK/Material: 19.1.2](https://github.com/angular/components/blob/19.1.2/src/cdk/tree/tree.ts) contains a fix [#30226](https://github.com/angular/components/pull/30226) but the issue still persists.

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.

WORKAROUND:

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

### Reproduction

StackBlitz link:

* Flat nodes: https://stackblitz.com/edit/jfoxsvj4?file=src%2Fexample%2Ftree-flat-child-accessor-overview-example.ts
* Nested nodes: https://stackblitz.com/edit/r8azqcn7?file=src%2Fexample%2Ftree-nested-child-accessor-overview-example.ts

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: 19.1.2
- CDK/Material: 19.1.2
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit src/cdk/tree/tree.ts bei expandAll() und vergleiche dann dessen Verhalten mit expandDescendants() und den verlinkten flachen und verschachtelten StackBlitz-Reproduktionen. Überprüfe die Änderung anhand beider Demos und bestätige, dass expandAll() jeden Knoten in einem tief verschachtelten Baum erweitert, nicht nur die erste Ebene.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.