Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow focusing date-picker input using keyboard on fullscreen #7577

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/date-picker/src/vaadin-date-picker-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { hideOthers } from '@vaadin/a11y-base/src/aria-hidden.js';
import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
Expand Down Expand Up @@ -459,7 +460,7 @@ export const DatePickerMixin = (subclass) =>
_onFocus(event) {
super._onFocus(event);

if (this._noInput) {
if (this._noInput && !isKeyboardActive()) {
event.target.blur();
}
}
Expand Down
26 changes: 25 additions & 1 deletion packages/date-picker/test/fullscreen.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextRender, nextUpdate, tap } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers';
import { sendKeys, setViewport } from '@web/test-runner-commands';
import sinon from 'sinon';
import { getFocusedCell, open, touchTap, waitForOverlayRender } from './helpers.js';
Expand Down Expand Up @@ -58,6 +58,14 @@ describe('fullscreen mode', () => {
expect(document.activeElement).to.not.equal(input);
});

it('should not blur input element when focusing it with keyboard', () => {
const spy = sinon.spy(input, 'blur');
tabKeyDown(input);
input.focus();
expect(spy.called).to.be.false;
expect(document.activeElement).to.equal(input);
});

it('should blur input element when opening overlay', async () => {
const spy = sinon.spy(input, 'blur');
await open(datePicker);
Expand All @@ -70,6 +78,22 @@ describe('fullscreen mode', () => {
expect(cell).to.be.instanceOf(HTMLTableCellElement);
expect(cell.getAttribute('part')).to.include('today');
});

it('should blur input element when closing overlay on outside click', async () => {
await open(datePicker);
const spy = sinon.spy(input, 'blur');
outsideClick();
await aTimeout(0);
expect(spy.called).to.be.true;
});

it('should not blur input element when closing overlay on Esc', async () => {
await open(datePicker);
const spy = sinon.spy(input, 'blur');
await sendKeys({ press: 'Escape' });
await aTimeout(0);
expect(spy.called).to.be.false;
});
});

describe('auto open disabled', () => {
Expand Down
Loading