bug(checkbox): Tri-state checkbox runs out of sync with its input after a change event
- Lingua principale
- TypeScript
- Stelle
- 25k
- Fork
- 6.8k
- Merge medio
- 1g 8h
- PR unite (30g)
- 91
Descrizione
### 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con la riproduzione StackBlitz collegata in src/main.ts e riproduci la transizione da indeterminate a unchecked tramite l'evento change della casella di controllo. Traccia il comportamento della casella di controllo a tre stati e verifica che lo stato visivo e lo stato dell'input rimangano sincronizzati dopo la modifica.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- angular, typescript
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100