Skip to content

Commit beb3492

Browse files
fix: do not validate fullscreen date-picker on internal blur while opening (#12434) (#12444)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent a1d2349 commit beb3492

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

packages/date-picker/src/vaadin-date-picker-mixin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ export const DatePickerMixin = (subclass) =>
401401
super._onFocus(event);
402402

403403
if (this._noInput && !isKeyboardActive()) {
404+
// Blur to hide the virtual keyboard, but do not validate.
405+
this.__ignoreInternalBlur = true;
404406
event.target.blur();
407+
this.__ignoreInternalBlur = false;
405408
}
406409
}
407410

@@ -412,6 +415,10 @@ export const DatePickerMixin = (subclass) =>
412415
_onBlur(event) {
413416
super._onBlur(event);
414417

418+
if (this.__ignoreInternalBlur) {
419+
return;
420+
}
421+
415422
if (!this.opened) {
416423
this.__commitParsedOrFocusedDate();
417424

packages/date-picker/test/fullscreen.test.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@vaadin/chai-plugins';
22
import { sendKeys, setViewport } from '@vaadin/test-runner-commands';
3-
import { aTimeout, fixtureSync, nextRender, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers';
3+
import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers';
44
import sinon from 'sinon';
55
import '../src/vaadin-date-picker.js';
66
import { getFocusableCell, open, touchTap, untilOverlayRendered } from './helpers.js';
@@ -156,6 +156,60 @@ describe('fullscreen mode', () => {
156156
});
157157
});
158158

159+
describe('validation', () => {
160+
let validateSpy;
161+
162+
beforeEach(async () => {
163+
datePicker.required = true;
164+
await nextUpdate(datePicker);
165+
validateSpy = sinon.spy(datePicker, 'validate');
166+
});
167+
168+
it('should not validate when focusing the input', () => {
169+
input.focus();
170+
expect(validateSpy.called).to.be.false;
171+
expect(datePicker.invalid).to.be.false;
172+
});
173+
174+
it('should not validate when opening overlay on input tap', async () => {
175+
input.focus();
176+
tap(input);
177+
await untilOverlayRendered(datePicker);
178+
expect(validateSpy.called).to.be.false;
179+
expect(datePicker.invalid).to.be.false;
180+
});
181+
182+
it('should validate when closing overlay on outside click', async () => {
183+
await open(datePicker);
184+
validateSpy.resetHistory();
185+
186+
outsideClick();
187+
await nextRender();
188+
189+
expect(validateSpy.called).to.be.true;
190+
expect(datePicker.invalid).to.be.true;
191+
});
192+
193+
it('should validate on blur after the input has been blurred internally', async () => {
194+
input.focus();
195+
tap(input);
196+
await untilOverlayRendered(datePicker);
197+
datePicker.close();
198+
await nextRender();
199+
200+
// Make the input focusable
201+
datePicker.autoOpenDisabled = true;
202+
await nextUpdate(datePicker);
203+
validateSpy.resetHistory();
204+
205+
input.focus();
206+
input.blur();
207+
208+
expect(validateSpy.called).to.be.true;
209+
expect(datePicker.invalid).to.be.true;
210+
});
211+
});
212+
159213
describe('buttons', () => {
160214
let overlayContent;
161215

0 commit comments

Comments
 (0)