Skip to content

Commit

Permalink
fix(material/timepicker): deserialize ControlValueAccessor values cor…
Browse files Browse the repository at this point in the history
…rectly (#30149)

Fixes that the timepicker was clobbering otherwise parseable values when they're assigned through the `ControlValueAccessor`.

Fixes #30140.

(cherry picked from commit f7d787b)
  • Loading branch information
crisbeto committed Dec 10, 2024
1 parent f8cf936 commit 600a8b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/material/timepicker/timepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ export class MatTimepickerInput<D> 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));
}

/**
Expand Down

0 comments on commit 600a8b0

Please sign in to comment.