Skip to content

Commit

Permalink
fix(material/datepicker): changed after checked error when assigning …
Browse files Browse the repository at this point in the history
…end value (#30534)

Fixes that there was a hidden "changed after checked" error in the range picker when the secondary value was being assinged without notifying Angular.

Fixes #30526.

(cherry picked from commit 7ef405c)
  • Loading branch information
crisbeto committed Feb 21, 2025
1 parent a41bcd4 commit 0a0ddcf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/material/datepicker/date-range-input-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ abstract class MatDateRangeInputPartBase<D>
opposite?._validatorOnChange();
}

protected override _formatValue(value: D | null) {
super._formatValue(value);
// Any time the input value is reformatted we need to tell the parent.
this._rangeInput._handleChildValueChange();
}

/** return the ARIA accessible name of the input element */
_getAccessibleName(): string {
return _computeAriaAccessibleName(this._elementRef.nativeElement);
Expand Down Expand Up @@ -264,16 +270,10 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
if (this._model) {
const range = new DateRange(value, this._model.selection.end);
this._model.updateSelection(range, this);
this._rangeInput._handleChildValueChange();
}
}

protected override _formatValue(value: D | null) {
super._formatValue(value);

// Any time the input value is reformatted we need to tell the parent.
this._rangeInput._handleChildValueChange();
}

override _onKeydown(event: KeyboardEvent) {
const endInput = this._rangeInput._endInput;
const element = this._elementRef.nativeElement;
Expand Down
2 changes: 0 additions & 2 deletions tools/public_api_guard/material/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ export class MatStartDate<D> extends MatDateRangeInputPartBase<D> {
// (undocumented)
protected _assignValueToModel(value: D | null): void;
// (undocumented)
protected _formatValue(value: D | null): void;
// (undocumented)
protected _getValueFromModel(modelValue: DateRange<D>): D | null;
// (undocumented)
_onKeydown(event: KeyboardEvent): void;
Expand Down

0 comments on commit 0a0ddcf

Please sign in to comment.