bug(checkbox): Tri-state checkbox runs out of sync with its input after a change event
- 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 think the direct implementation with the `(change)` checkbox output (represented in https://stackblitz.com/edit/angular-tzjh4u?file=src%2Fmain.ts) has never worked.
With the Legacy checkbox, we had a workaround that relied on `click` and `keyup.space` DOM events instead of relying on the component's `change` output.
After migrating to MDC, this workaround no longer works, too.
### Reproduction
https://stackblitz.com/edit/angular-tzjh4u?file=src%2Fmain.ts
Steps to reproduce:
1. Click checkbox to toggle between "checked" and "unchecked" - see how the checkbox state (checkmark) is always in sync with the app state (`this.state`)
2. Click the "Set to indeterminate" button
3. Click the checkbox, which is currently in the indeterminate state
### Expected Behavior
Checkbox becomes "unchecked"
### Actual Behavior
Checkbox becomes "checked", despite `this.state` is "unchecked". Checkbox is now out of sync with its input. Note how `ng-reflect-checked="false"`, while the classname includes `mat-mdc-checkbox-checked`
### Environment
- Angular 16.0.2
- CDK/Material: 16.0.1
- Browser(s): Firefox, Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với bản tái hiện StackBlitz được liên kết tại src/main.ts và tái hiện quá trình chuyển từ indeterminate sang unchecked thông qua sự kiện change của checkbox. Theo dõi hành vi của checkbox ba trạng thái và xác minh rằng trạng thái trực quan và trạng thái input vẫn đồng bộ sau khi thay đổi.
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