bug(checkbox): Tri-state checkbox runs out of sync with its input after a change event
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
### 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
コントリビューションガイド
調査の方向性
src/main.ts にあるリンク先の StackBlitz の再現から始め、チェックボックスの change イベントを通じて indeterminate から unchecked への遷移を再現します。三状態チェックボックスの動作を追跡し、変更後も視覚状態と input 状態の同期が保たれていることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100