Skip to content

Commit de5f989

Browse files
authored
fix: do not fire change event for time-picker bad input (#6371)
1 parent 18945c3 commit de5f989

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎packages/time-picker/src/vaadin-time-picker.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
630630
/** @private */
631631
__onComboBoxChange(event) {
632632
event.stopPropagation();
633-
this.__dispatchChange();
633+
634+
const { value } = event.target;
635+
// Do not fire change for bad input.
636+
if (value === '' || this.i18n.parseTime(value)) {
637+
this.__dispatchChange();
638+
}
634639
}
635640

636641
/**

‎packages/time-picker/test/validation.test.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('validation', () => {
101101
expect(validateSpy.calledOnce).to.be.true;
102102
});
103103

104-
it('should validate before change event on outside click', async () => {
104+
it('should validate before change event on outside click', () => {
105105
input.focus();
106106
input.click();
107107
setInputValue(timePicker, '12:00');
@@ -111,6 +111,15 @@ describe('validation', () => {
111111
expect(validateSpy.calledBefore(changeSpy)).to.be.true;
112112
});
113113

114+
it('should validate without change event on bad input', () => {
115+
input.focus();
116+
input.click();
117+
setInputValue(timePicker, 'foo');
118+
outsideClick();
119+
expect(changeSpy.called).to.be.false;
120+
expect(validateSpy.calledOnce).to.be.true;
121+
});
122+
114123
it('should validate before change event on blur', () => {
115124
input.focus();
116125
setInputValue(timePicker, '12:00');

0 commit comments

Comments
 (0)