angular / angular/components

bug(mat-tree): How to maintain tree expansion state if TreeControl is deprecated?

Đang mở
#30,258 8 bình luận 9 reaction 0 người được giao Xem trên GitHub
area: cdk/tree P3
Ngôn ngữ chính
TypeScript
Star
25k
Fork
6.8k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
91

Mô tả

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

pre v18.2.0

### Description

Previously, it was possible to maintain the expansion state independent of the MatTree (rendered) component by using a TreeControl.

With TreeControl deprecated, this does not appear possible any longer.

I rely on this feature so would appreciate consideration of a path forward.

Of note, the selection model is maintained privately in MatTree:
https://github.com/angular/components/blob/b961966d285c1f4986d214084ff585a713adc3bd/src/cdk/tree/tree.ts#L366-L372

Note that this is not a duplicate of #29856, which looks to relate to accessing some of the methods of TreeControl, which have been made available on MatTree itself.

### Reproduction

I can produce a reproduction but I believe the regression has been clearly explained above and a reproduction does not add value.

### Expected Behavior

There is a mechanism for maintaining expansion state independent of the rendered component.

### Actual Behavior

Expansion state is lost when the component is destroyed.

### Environment

```
Angular CLI: 18.0.3
Node: 18.20.5
Package Manager: npm 10.8.2
OS: darwin arm64

Angular: 18.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1800.3
@angular-devkit/build-angular 18.0.3
@angular-devkit/core 18.0.3
@angular-devkit/schematics 18.0.3
@angular/cdk 18.2.14
@angular/cli 18.0.3
@angular/flex-layout 14.0.0-beta.41
@angular/material 18.2.14
@angular/material-luxon-adapter 18.2.14
@schematics/angular 18.0.3
ng-packagr 18.0.0
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.4
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with src/cdk/tree/tree.ts, especially the private selection model referenced in the issue, and trace how MatTree and the deprecated TreeControl manage expansion. Determine an API or state mechanism that preserves expansion independently of the rendered component. Done means expansion state survives component destruction and is covered by the relevant tree behavior tests.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
frontend
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.