Skip to content

Commit 0fa4cd8

Browse files
fix: allow focusing date-picker input using keyboard on fullscreen (#7577) (#7581)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent ecbfb87 commit 0fa4cd8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import { hideOthers } from '@vaadin/a11y-base/src/aria-hidden.js';
77
import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
8+
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
89
import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
910
import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
1011
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
@@ -448,7 +449,7 @@ export const DatePickerMixin = (subclass) =>
448449
_onFocus(event) {
449450
super._onFocus(event);
450451

451-
if (this._noInput) {
452+
if (this._noInput && !isKeyboardActive()) {
452453
event.target.blur();
453454
}
454455
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextRender, nextUpdate, tap } from '@vaadin/testing-helpers';
2+
import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers';
33
import { sendKeys, setViewport } from '@web/test-runner-commands';
44
import sinon from 'sinon';
55
import { getFocusedCell, open, touchTap, waitForOverlayRender } from './helpers.js';
@@ -58,6 +58,14 @@ describe('fullscreen mode', () => {
5858
expect(document.activeElement).to.not.equal(input);
5959
});
6060

61+
it('should not blur input element when focusing it with keyboard', () => {
62+
const spy = sinon.spy(input, 'blur');
63+
tabKeyDown(input);
64+
input.focus();
65+
expect(spy.called).to.be.false;
66+
expect(document.activeElement).to.equal(input);
67+
});
68+
6169
it('should blur input element when opening overlay', async () => {
6270
const spy = sinon.spy(input, 'blur');
6371
await open(datePicker);
@@ -70,6 +78,22 @@ describe('fullscreen mode', () => {
7078
expect(cell).to.be.instanceOf(HTMLTableCellElement);
7179
expect(cell.getAttribute('part')).to.include('today');
7280
});
81+
82+
it('should blur input element when closing overlay on outside click', async () => {
83+
await open(datePicker);
84+
const spy = sinon.spy(input, 'blur');
85+
outsideClick();
86+
await aTimeout(0);
87+
expect(spy.called).to.be.true;
88+
});
89+
90+
it('should not blur input element when closing overlay on Esc', async () => {
91+
await open(datePicker);
92+
const spy = sinon.spy(input, 'blur');
93+
await sendKeys({ press: 'Escape' });
94+
await aTimeout(0);
95+
expect(spy.called).to.be.false;
96+
});
7397
});
7498

7599
describe('auto open disabled', () => {

0 commit comments

Comments
 (0)