angular / angular/components

Use of custom TrackByFunction in MatTree does not preserve expansion state when nodes change

Đang mở
#15,872 8 bình luận 17 reaction 0 người được giao Xem trên GitHub
area: material/tree G P2
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ả

#### What is the expected behavior?

Use of trackBy should also ensure that the expansion state does not get lost when nodes are updated.

#### What is the current behavior?

Use of trackBy does not ensure that the expansion state does not get lost when nodes are updated. This is presumably since TreeControl uses an expansionModel which is a SelectionModel where the SelectionModel has no awareness of the TrackByFunction.

#### What are the steps to reproduce?

Relying upon the TreeControl expansionModel:
https://stackblitz.com/edit/angular-5wpr9o-kjnmsn?file=app%2Ftree-flat-overview-example.ts

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?

all

#### Is there anything else we should know?

Trying to store expansion state in the nodes themselves as a workaround doesn't work (unless you transfer the state):
https://stackblitz.com/edit/angular-5wpr9o-ahptjs?file=app%2Ftree-flat-overview-example.ts

Having a custom expansionModel that is aware of the trackBy state works to preserve state, since the TreeControl's expansion-related methods apparently aren't actually used internally by the tree component:
https://stackblitz.com/edit/angular-5wpr9o-pbmk1g?file=app%2Ftree-flat-overview-example.ts

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

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

Hướng nghiên cứu

Bắt đầu với các bản tái hiện StackBlitz được liên kết, đặc biệt là app/tree-flat-overview-example.ts, và kiểm tra cách MatTree, TreeControl, TrackByFunction và expansionModel tương tác với nhau. Tái hiện việc mất trạng thái mở rộng khi các node được cập nhật bằng một trackBy tùy chỉnh. Được xem là hoàn tất khi trạng thái mở rộng vẫn được giữ nguyên sau các lần cập nhật đó.

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ó
4/5
Thời gian dự kiến
3-5 ngày
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
38/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.