chore(calendar): different event key names
This commit is contained in:
parent
224f794a1e
commit
eb768c061d
4 changed files with 2 additions and 84 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { html, LitElement } from '@lion/core';
|
import { html, LitElement } from '@lion/core';
|
||||||
import { localize, getWeekdayNames, getMonthNames, LocalizeMixin } from '@lion/localize';
|
import { localize, getWeekdayNames, getMonthNames, LocalizeMixin } from '@lion/localize';
|
||||||
|
import '@lion/core/src/differentKeyEventNamesShimIE.js';
|
||||||
import { createMultipleMonth } from './utils/createMultipleMonth.js';
|
import { createMultipleMonth } from './utils/createMultipleMonth.js';
|
||||||
import { dayTemplate } from './utils/dayTemplate.js';
|
import { dayTemplate } from './utils/dayTemplate.js';
|
||||||
import { dataTemplate } from './utils/dataTemplate.js';
|
import { dataTemplate } from './utils/dataTemplate.js';
|
||||||
|
|
@ -7,7 +8,6 @@ import { getFirstDayNextMonth } from './utils/getFirstDayNextMonth.js';
|
||||||
import { getLastDayPreviousMonth } from './utils/getLastDayPreviousMonth.js';
|
import { getLastDayPreviousMonth } from './utils/getLastDayPreviousMonth.js';
|
||||||
import { isSameDate } from './utils/isSameDate.js';
|
import { isSameDate } from './utils/isSameDate.js';
|
||||||
import { calendarStyle } from './calendarStyle.js';
|
import { calendarStyle } from './calendarStyle.js';
|
||||||
import './utils/differentKeyNamesShimIE.js';
|
|
||||||
import { createDay } from './utils/createDay.js';
|
import { createDay } from './utils/createDay.js';
|
||||||
import { normalizeDateTime } from './utils/normalizeDateTime.js';
|
import { normalizeDateTime } from './utils/normalizeDateTime.js';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
const event = KeyboardEvent.prototype;
|
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(event, 'key');
|
|
||||||
if (descriptor) {
|
|
||||||
const keys = {
|
|
||||||
Win: 'Meta',
|
|
||||||
Scroll: 'ScrollLock',
|
|
||||||
Spacebar: ' ',
|
|
||||||
|
|
||||||
Down: 'ArrowDown',
|
|
||||||
Left: 'ArrowLeft',
|
|
||||||
Right: 'ArrowRight',
|
|
||||||
Up: 'ArrowUp',
|
|
||||||
|
|
||||||
Del: 'Delete',
|
|
||||||
Apps: 'ContextMenu',
|
|
||||||
Esc: 'Escape',
|
|
||||||
|
|
||||||
Multiply: '*',
|
|
||||||
Add: '+',
|
|
||||||
Subtract: '-',
|
|
||||||
Decimal: '.',
|
|
||||||
Divide: '/',
|
|
||||||
};
|
|
||||||
Object.defineProperty(event, 'key', {
|
|
||||||
// eslint-disable-next-line object-shorthand, func-names
|
|
||||||
get: function() {
|
|
||||||
const key = descriptor.get.call(this);
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-prototype-builtins
|
|
||||||
return keys.hasOwnProperty(key) ? keys[key] : key;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
if (typeof window.KeyboardEvent !== 'function') {
|
|
||||||
// e.g. is IE and needs "polyfill"
|
|
||||||
const KeyboardEvent = (event, _params) => {
|
|
||||||
// current spec for it https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent
|
|
||||||
const params = {
|
|
||||||
bubbles: false,
|
|
||||||
cancelable: false,
|
|
||||||
view: document.defaultView,
|
|
||||||
key: false,
|
|
||||||
location: false,
|
|
||||||
ctrlKey: false,
|
|
||||||
shiftKey: false,
|
|
||||||
altKey: false,
|
|
||||||
metaKey: false,
|
|
||||||
repeat: false,
|
|
||||||
..._params,
|
|
||||||
};
|
|
||||||
const modifiersListArray = [];
|
|
||||||
if (params.ctrlKey) {
|
|
||||||
modifiersListArray.push('Control');
|
|
||||||
}
|
|
||||||
if (params.shiftKey) {
|
|
||||||
modifiersListArray.push('Shift');
|
|
||||||
}
|
|
||||||
if (params.altKey) {
|
|
||||||
modifiersListArray.push('Alt');
|
|
||||||
}
|
|
||||||
if (params.metaKey) {
|
|
||||||
modifiersListArray.push('Meta');
|
|
||||||
}
|
|
||||||
|
|
||||||
const ev = document.createEvent('KeyboardEvent');
|
|
||||||
// IE Spec for it https://technet.microsoft.com/en-us/windows/ff975297(v=vs.60)
|
|
||||||
ev.initKeyboardEvent(
|
|
||||||
event,
|
|
||||||
params.bubbles,
|
|
||||||
params.cancelable,
|
|
||||||
params.view,
|
|
||||||
params.key,
|
|
||||||
params.location,
|
|
||||||
modifiersListArray.join(' '),
|
|
||||||
params.repeat ? 1 : 0,
|
|
||||||
params.locale,
|
|
||||||
);
|
|
||||||
return ev;
|
|
||||||
};
|
|
||||||
KeyboardEvent.prototype = window.Event.prototype;
|
|
||||||
window.KeyboardEvent = KeyboardEvent;
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { expect, fixture } from '@open-wc/testing';
|
import { expect, fixture } from '@open-wc/testing';
|
||||||
|
import '@lion/core/test-helpers/keyboardEventShimIE.js';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import { html } from '@lion/core';
|
import { html } from '@lion/core';
|
||||||
|
|
@ -6,7 +7,6 @@ import { localize } from '@lion/localize';
|
||||||
import { localizeTearDown } from '@lion/localize/test-helpers.js';
|
import { localizeTearDown } from '@lion/localize/test-helpers.js';
|
||||||
|
|
||||||
import { CalendarObject, DayObject } from '../test-helpers.js';
|
import { CalendarObject, DayObject } from '../test-helpers.js';
|
||||||
import './keyboardEventShimIE.js';
|
|
||||||
|
|
||||||
import { isSameDate } from '../src/utils/isSameDate.js';
|
import { isSameDate } from '../src/utils/isSameDate.js';
|
||||||
import '../lion-calendar.js';
|
import '../lion-calendar.js';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue