Skip to content

Commit 2219b11

Browse files
authored
fix(material/timepicker): don't mark as touched when blurred while dropdown is open (#30228)
Fixes that the timepicker was marking itself as touched too early when clicking on an item in the dropdown. Fixes #30223.
1 parent e421765 commit 2219b11

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/material/timepicker/timepicker-input.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ export class MatTimepickerInput<D> implements ControlValueAccessor, Validator, O
285285
this._formatValue(value);
286286
}
287287

288-
this._onTouched?.();
288+
if (!this.timepicker().isOpen()) {
289+
this._onTouched?.();
290+
}
289291
}
290292

291293
/** Handles the `keydown` event. */

src/material/timepicker/timepicker.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,18 @@ describe('MatTimepicker', () => {
955955
fixture.detectChanges();
956956
expect(fixture.componentInstance.control.touched).toBe(false);
957957

958+
getInput(fixture).click();
959+
fixture.detectChanges();
960+
dispatchFakeEvent(getInput(fixture), 'blur');
961+
fixture.detectChanges();
962+
expect(fixture.componentInstance.control.touched).toBe(false);
963+
});
964+
965+
it('should mark the control as touched on blur while dropdown is open', () => {
966+
const fixture = TestBed.createComponent(TimepickerWithForms);
967+
fixture.detectChanges();
968+
expect(fixture.componentInstance.control.touched).toBe(false);
969+
958970
dispatchFakeEvent(getInput(fixture), 'blur');
959971
fixture.detectChanges();
960972
expect(fixture.componentInstance.control.touched).toBe(true);

0 commit comments

Comments
 (0)