angular / angular/components

bug(checkbox): Tri-state checkbox runs out of sync with its input after a change event

Abierto
#27,150 0 comentarios 3 reacciones 0 asignados Ver en GitHub
area: material/checkbox P3
Lenguaje dominante
TypeScript
Estrellas
25k
Forks
6.8k
Merge medio
1 d 8 h
PR fusionados (30 d)
91

Descripción

### 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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con la reproducción enlazada de StackBlitz en src/main.ts y reproduce la transición de indeterminate a unchecked mediante el evento change de la casilla de verificación. Rastrea el comportamiento de la casilla de verificación de tres estados y verifica que el estado visual y el estado del input sigan sincronizados después del cambio.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
angular, typescript
Área
frontend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.