fix(datepicker): changed after checked error if focused datepicker inputs turn disabled (#9717)

In some situations, the `disable()` method of a form control is called while the datepicker input is focused. This causes a changed after checked error.

Normally, native input elements automatically blur if they turn disabled. This behavior is problematic, because it would mean that it triggers another change detection cycle, which then causes a changed after checked error if the input element was focused before.

Fixes #9559
This commit is contained in:
Paul Gschwendtner
2018-02-08 22:42:14 +01:00
committed by mmalerba
parent df0bfdcc7b
commit 46c809728d
+7
View File
@@ -161,6 +161,13 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
this._disabled = newValue;
this._disabledChange.emit(newValue);
}
if (newValue) {
// Normally, native input elements automatically blur if they turn disabled. This behavior
// is problematic, because it would mean that it triggers another change detection cycle,
// which then causes a changed after checked error if the input element was focused before.
this._elementRef.nativeElement.blur();
}
}
private _disabled: boolean;