bug(mat-checkbox): Setting value programmatically from changed listener detaches state from template #22149
Labels
Accessibility
This issue is related to accessibility (a11y)
area: material/checkbox
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Reproduction
Use StackBlitz to reproduce your issue:
https://stackblitz.com/edit/angular-ivy-zppefd?file=src%2Fapp%2Fapp.component.ts
Steps to reproduce:
input
s, and incorrectly format-checkbox
.Expected Behavior
What behavior were you expecting to see?
input
element should appropriately represent thechecked
property.Actual Behavior
What behavior did you actually see?
controls['control'].setValue(value)
within the(changed)
listener, the JavaScript state becomes out of sync with the DOM and thechecked
property is not set accurately.setValue()
command from the tick stack withsetTimeout()
allows a subsequent digest to capture the change and keep things in sync. (seeapp.component.ts
)..mat-checkbox-checked
class as opposed to relying on the:checked
pseudo-class. Commenting / uncommenting the style@import
reveals the state mismatch by showing the underlyinginput
.Environment
The text was updated successfully, but these errors were encountered: