angular / angular/components

bug(mat-selection-list): mat-list-option deselecting itself when recreated in virtual-scroll-viewport

Đang mở
#29,426 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
area: material/list P4
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?

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

### The previous version in which this bug was not present was

_No response_

### Description

I have a wrapper component for the `mat-selection-list` to support generic filtering. Also I have a master checkbox to select everything in the current filter scope. To support large datasets I also have an option for `virtual scrolling`.

Since I allow filtering, the source set of the list is constantly changing which clears the selection if an option is filtered out. To prevent this, I use the angular `SelectionModel` and the callbacks of the mat-list-options. But here is the problem:

Since the options are destroyed and recreated while scrolling through the viewport, the `selectedChange` event of the option is triggered with the initial unselected state of an option, so an option deselects itself when being recreated. But since this does not happen all the time, it seems there is a race between `(selectedChange)` and `[selected]`.

### Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-iidbcx
Steps to reproduce:
1. Trigger the master check-box
2. scroll
3. see the master changes to indeterminate since check-boxes deselect themself

### Expected Behavior

I would expect that the inital `selected = false` when creating the component is not emitted as an event

### Actual Behavior

Inital `selected = false` when creating the component is emitted as an event and selected itself. But not always --> race

### Environment

Angular CLI: 18.0.7
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.0.6
... animations, cdk, cdk-experimental, common, compiler
... compiler-cli, core, forms, material, platform-browser
... platform-browser-dynamic, router

Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1800.7
@angular-devkit/build-angular 18.0.7
@angular-devkit/core 18.0.7
@angular-devkit/schematics 18.0.7
@angular/cli 18.0.7
@schematics/angular 18.0.7
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.7

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 bản tái hiện trên StackBlitz và kiểm tra sự tương tác giữa mat-selection-list, mat-list-option và virtual-scroll-viewport khi cuộn sau khi đã chọn tất cả các mục. Xác minh rằng việc tạo lại một option không phát ra sự kiện selectedChange ban đầu với false và rằng lựa chọn chính vẫn ổn định sau khi lọc và cuộn.

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
35/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.