Skip to content

Commit

Permalink
fix(material/timepicker): don't mark as touched when blurred while dr…
Browse files Browse the repository at this point in the history
…opdown is open

Fixes that the timepicker was marking itself as touched too early when clicking on an item in the dropdown.

Fixes #30223.
  • Loading branch information
crisbeto committed Dec 23, 2024
1 parent 9cd1d30 commit 0d8a400
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/material/timepicker/timepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ export class MatTimepickerInput<D> implements ControlValueAccessor, Validator, O
this._formatValue(value);
}

this._onTouched?.();
if (!this.timepicker().isOpen()) {
this._onTouched?.();
}
}

/** Handles the `keydown` event. */
Expand Down
12 changes: 12 additions & 0 deletions src/material/timepicker/timepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,18 @@ describe('MatTimepicker', () => {
fixture.detectChanges();
expect(fixture.componentInstance.control.touched).toBe(false);

getInput(fixture).click();
fixture.detectChanges();
dispatchFakeEvent(getInput(fixture), 'blur');
fixture.detectChanges();
expect(fixture.componentInstance.control.touched).toBe(false);
});

it('should mark the control as touched on blur while dropdown is open', () => {
const fixture = TestBed.createComponent(TimepickerWithForms);
fixture.detectChanges();
expect(fixture.componentInstance.control.touched).toBe(false);

dispatchFakeEvent(getInput(fixture), 'blur');
fixture.detectChanges();
expect(fixture.componentInstance.control.touched).toBe(true);
Expand Down

0 comments on commit 0d8a400

Please sign in to comment.