From f844ed1bebf05a41a4c4dd77d6f71bf10d2a290c Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 9 Dec 2024 10:49:33 +0100 Subject: [PATCH] fix(material/timepicker): deserialize ControlValueAccessor values correctly Fixes that the timepicker was clobbering otherwise parseable values when they're assigned through the `ControlValueAccessor`. Fixes #30140. --- src/material/timepicker/timepicker-input.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/material/timepicker/timepicker-input.ts b/src/material/timepicker/timepicker-input.ts index 54f088f7dd28..cba7e2522f63 100644 --- a/src/material/timepicker/timepicker-input.ts +++ b/src/material/timepicker/timepicker-input.ts @@ -178,7 +178,11 @@ export class MatTimepickerInput implements ControlValueAccessor, Validator, O * @docs-private */ writeValue(value: any): void { - this.value.set(this._dateAdapter.getValidDateOrNull(value)); + // Note that we need to deserialize here, rather than depend on the value change effect, + // because `getValidDateOrNull` will clobber the value if it's parseable, but not created by + // the current adapter (see #30140). + const deserialized = this._dateAdapter.deserialize(value); + this.value.set(this._dateAdapter.getValidDateOrNull(deserialized)); } /**