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`).
This commit is contained in:
Paul Gschwendtner
2019-05-23 16:50:18 +02:00
committed by mmalerba
parent 9bb09ebd89
commit 6cf2dd2203
@@ -120,6 +120,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
}
set checked(checked) {
this._checked = coerceBooleanProperty(checked);
this._changeDetectorRef.markForCheck();
}
private _checked = false;
@@ -135,6 +136,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
}
set indeterminate(indeterminate) {
this._indeterminate = coerceBooleanProperty(indeterminate);
this._changeDetectorRef.markForCheck();
}
private _indeterminate = false;
@@ -156,6 +158,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
}
set required(required) {
this._required = coerceBooleanProperty(required);
this._changeDetectorRef.markForCheck();
}
private _required = false;