Skip to content

Commit 6cf2dd2

Browse files
devversionmmalerba
authored andcommitted
chore: fix mdc-checkbox not working with ivy
Fixes that the `mdc-checkbox` prototype does not work properly with Ivy as there are component inputs which are commonly set programmatically but do not mark the checkbox as dirty. This surfaced in one of the checkbox tests because with Ivy, calling `markForCheck` from within the `ngAfterViewInit` lifecycle hook has basically no effect while View Engine keeps the component dirty. This caused a checkbox test failure because the test just assigned the value of the `MatCheckbox#checked` property and called `detectChanges` afterwards. Since the component is not marked as dirty due to the aforementioned Ivy difference, the component will not be checked and updated. In order to fix the test we just mark the component for check in the input setters (similarly to how we do it for other inputs of `MatCheckbox` such as `disabled`).
1 parent 9bb09eb commit 6cf2dd2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/material-experimental/mdc-checkbox/checkbox.ts

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
120120
}
121121
set checked(checked) {
122122
this._checked = coerceBooleanProperty(checked);
123+
this._changeDetectorRef.markForCheck();
123124
}
124125
private _checked = false;
125126

@@ -135,6 +136,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
135136
}
136137
set indeterminate(indeterminate) {
137138
this._indeterminate = coerceBooleanProperty(indeterminate);
139+
this._changeDetectorRef.markForCheck();
138140
}
139141
private _indeterminate = false;
140142

@@ -156,6 +158,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
156158
}
157159
set required(required) {
158160
this._required = coerceBooleanProperty(required);
161+
this._changeDetectorRef.markForCheck();
159162
}
160163
private _required = false;
161164

0 commit comments

Comments
 (0)