Skip to content

Commit 01ad7bd

Browse files
devversionmmalerba
authored andcommitted
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
1 parent cd159f5 commit 01ad7bd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib/datepicker/datepicker-input.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
161161
this._disabled = newValue;
162162
this._disabledChange.emit(newValue);
163163
}
164+
165+
if (newValue) {
166+
// Normally, native input elements automatically blur if they turn disabled. This behavior
167+
// is problematic, because it would mean that it triggers another change detection cycle,
168+
// which then causes a changed after checked error if the input element was focused before.
169+
this._elementRef.nativeElement.blur();
170+
}
164171
}
165172
private _disabled: boolean;
166173

0 commit comments

Comments
 (0)