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

refactor: remove IronA11yKeysBehavior dependency #3005

Merged
merged 2 commits into from
Nov 10, 2021
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
1 change: 0 additions & 1 deletion packages/date-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@open-wc/dedupe-mixin": "^1.3.0",
"@polymer/iron-a11y-announcer": "^3.0.0",
"@polymer/iron-a11y-keys-behavior": "^3.0.0",
"@polymer/iron-media-query": "^3.0.0",
"@polymer/polymer": "^3.2.0",
"@vaadin/button": "22.0.0-beta1",
Expand Down
28 changes: 6 additions & 22 deletions packages/date-picker/src/vaadin-date-picker-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (c) 2021 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { IronA11yKeysBehavior } from '@polymer/iron-a11y-keys-behavior/iron-a11y-keys-behavior.js';
import { addListener } from '@polymer/polymer/lib/utils/gestures.js';
import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js';
Expand Down Expand Up @@ -824,21 +823,6 @@ export const DatePickerMixin = (subclass) =>
}
}

/**
* Keyboard Navigation
* @private
*/
_eventKey(e) {
const keys = ['down', 'up', 'enter', 'esc', 'tab'];

for (let i = 0; i < keys.length; i++) {
const k = keys[i];
if (IronA11yKeysBehavior.keyboardEventMatchesKeys(e, k)) {
return k;
}
}
}

/** @private */
_isValidDate(d) {
return d && !isNaN(d.getTime());
Expand Down Expand Up @@ -893,9 +877,9 @@ export const DatePickerMixin = (subclass) =>
}
}

switch (this._eventKey(e)) {
case 'down':
case 'up':
switch (e.key) {
case 'ArrowDown':
case 'ArrowUp':
// prevent scrolling the page with arrows
e.preventDefault();

Expand All @@ -908,7 +892,7 @@ export const DatePickerMixin = (subclass) =>
}

break;
case 'enter': {
case 'Enter': {
const parsedDate = this._getParsedDate();
const isValidDate = this._isValidDate(parsedDate);
if (this.opened) {
Expand All @@ -929,7 +913,7 @@ export const DatePickerMixin = (subclass) =>
}
break;
}
case 'esc':
case 'Escape':
if (this.opened) {
this._focusedDate = this._selectedDate;
this._close();
Expand All @@ -946,7 +930,7 @@ export const DatePickerMixin = (subclass) =>
this._selectParsedOrFocusedDate();
}
break;
case 'tab':
case 'Tab':
if (this.opened) {
e.preventDefault();
//Clear the selection range (remains visible on IE)
Expand Down
59 changes: 30 additions & 29 deletions packages/date-picker/src/vaadin-date-picker-overlay-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import '@vaadin/button/src/vaadin-button.js';
import './vaadin-month-calendar.js';
import './vaadin-infinite-scroller.js';
import { IronA11yAnnouncer } from '@polymer/iron-a11y-announcer/iron-a11y-announcer.js';
import { IronA11yKeysBehavior } from '@polymer/iron-a11y-keys-behavior/iron-a11y-keys-behavior.js';
import { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
import { addListener, setTouchAction } from '@polymer/polymer/lib/utils/gestures.js';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
Expand Down Expand Up @@ -704,20 +703,6 @@ class DatePickerOverlayContent extends ThemableMixin(DirMixin(GestureEventListen
e.preventDefault();
}

/**
* Keyboard Navigation
*/
_eventKey(e) {
var keys = ['down', 'up', 'right', 'left', 'enter', 'space', 'home', 'end', 'pageup', 'pagedown', 'tab', 'esc'];

for (var i = 0; i < keys.length; i++) {
var k = keys[i];
if (IronA11yKeysBehavior.keyboardEventMatchesKeys(e, k)) {
return k;
}
}
}

_onKeydown(e) {
var focus = this._currentlyFocusedDate();

Expand All @@ -727,8 +712,24 @@ class DatePickerOverlayContent extends ThemableMixin(DirMixin(GestureEventListen
const isCancel = e.composedPath().indexOf(this.$.cancelButton) >= 0;
const isScroller = !isToday && !isCancel;

var eventKey = this._eventKey(e);
if (eventKey === 'tab') {
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
const navigationKeys = [
' ',
'ArrowDown',
'ArrowUp',
'ArrowRight',
'ArrowLeft',
'Enter',
'End',
'Escape',
'Home',
'PageUp',
'PageDown',
'Tab'
];

const eventKey = e.key;
if (eventKey === 'Tab') {
// We handle tabs here and don't want to bubble up.
e.stopPropagation();

Expand All @@ -751,36 +752,36 @@ class DatePickerOverlayContent extends ThemableMixin(DirMixin(GestureEventListen
// set to false.
this._focused = false;
}
} else if (eventKey) {
} else if (navigationKeys.includes(eventKey)) {
e.preventDefault();
e.stopPropagation();
switch (eventKey) {
case 'down':
case 'ArrowDown':
this._moveFocusByDays(7);
this.focus();
break;
case 'up':
case 'ArrowUp':
this._moveFocusByDays(-7);
this.focus();
break;
case 'right':
case 'ArrowRight':
if (isScroller) {
this._moveFocusByDays(this.__isRTL ? -1 : 1);
}
break;
case 'left':
case 'ArrowLeft':
if (isScroller) {
this._moveFocusByDays(this.__isRTL ? 1 : -1);
}
break;
case 'enter':
case 'Enter':
if (isScroller || isCancel) {
this._close();
} else if (isToday) {
this._onTodayTap();
}
break;
case 'space':
case ' ':
if (isCancel) {
this._close();
} else if (isToday) {
Expand All @@ -795,19 +796,19 @@ class DatePickerOverlayContent extends ThemableMixin(DirMixin(GestureEventListen
}
}
break;
case 'home':
case 'Home':
this._moveFocusInsideMonth(focus, 'minDate');
break;
case 'end':
case 'End':
this._moveFocusInsideMonth(focus, 'maxDate');
break;
case 'pagedown':
case 'PageDown':
this._moveFocusByMonths(e.shiftKey ? 12 : 1);
break;
case 'pageup':
case 'PageUp':
this._moveFocusByMonths(e.shiftKey ? -12 : -1);
break;
case 'esc':
case 'Escape':
this._cancel();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@
dependencies:
"@polymer/polymer" "^3.0.0"

"@polymer/iron-a11y-keys-behavior@^3.0.0", "@polymer/iron-a11y-keys-behavior@^3.0.0-pre.26":
"@polymer/iron-a11y-keys-behavior@^3.0.0-pre.26":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@polymer/iron-a11y-keys-behavior/-/iron-a11y-keys-behavior-3.0.1.tgz#2868ea72912d2007ffab4734684a91f5aac49b84"
integrity sha512-lnrjKq3ysbBPT/74l0Fj0U9H9C35Tpw2C/tpJ8a+5g8Y3YJs1WSZYnEl1yOkw6sEyaxOq/1DkzH0+60gGu5/PQ==
Expand Down