Skip to content

Commit

Permalink
chore: stop using deprecated KeyboardEvent.keyCode
Browse files Browse the repository at this point in the history
Fixes #861
  • Loading branch information
pdesoyres-cc committed Oct 2, 2024
1 parent d625616 commit b407125
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/cc-input-number/cc-input-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../cc-icon/cc-icon.js';
* @typedef {import('lit/directives/ref.js').Ref<HTMLInputElement>} HTMLInputElementRef
* @typedef {import('lit/directives/ref.js').Ref<HTMLElement>} HTMLElementRef
* @typedef {import('../../lib/events.types.js').EventWithTarget<HTMLInputElement>} HTMLInputElementEvent
* @typedef {import('../../lib/events.types.js').GenericEventWithTarget<KeyboardEvent, HTMLInputElement>} HTMLInputElementKeyEvent
* @typedef {import('../../lib/form/validation.types.js').ErrorMessageMap} ErrorMessageMap
* @typedef {import('../../lib/form/validation.types.js').Validator} Validator
* @typedef {import('../../lib/form/form.types.js').FormControlData} FormControlData
Expand Down Expand Up @@ -208,20 +209,20 @@ export class CcInputNumber extends CcFormControlElement {
/**
* Stop propagation of keydown and keypress events (to prevent conflicts with shortcuts)
*
* @param {HTMLInputElementEvent & { keyCode: number}} e
* @param {HTMLInputElementKeyEvent} e
*/
_onKeyEvent(e) {
if (e.type === 'keydown' || e.type === 'keypress') {
e.stopPropagation();
}
// Here we prevent keydown on enter key from modifying the value
if (e.type === 'keydown' && e.keyCode === 13) {
if (e.type === 'keydown' && e.key === 'Enter') {
e.preventDefault();
this._internals.form?.requestSubmit();
dispatchCustomEvent(this, 'requestimplicitsubmit');
}
// Request implicit submit with keypress on enter key
if (!this.readonly && e.type === 'keypress' && e.keyCode === 13) {
if (!this.readonly && e.type === 'keypress' && e.key === 'Enter') {
this._internals.form?.requestSubmit();
dispatchCustomEvent(this, 'requestimplicitsubmit');
}
Expand Down
5 changes: 2 additions & 3 deletions src/stories/lib/i18n-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ setLanguage(INIT_LANG);

const ALL_LANGS = availableLanguages.map((o) => o.value);

window.addEventListener('keypress', ({ keyCode, altKey, ctrlKey, metaKey, shiftKey }) => {
// "i" key
if (keyCode === 105 && !altKey && !ctrlKey && !metaKey && !shiftKey) {
window.addEventListener('keypress', ({ key, altKey, ctrlKey, metaKey, shiftKey }) => {
if (key === 'i' && !altKey && !ctrlKey && !metaKey && !shiftKey) {
const langIdx = ALL_LANGS.indexOf(getLanguage());
const nextIdx = (langIdx + 1) % ALL_LANGS.length;
const nextLang = ALL_LANGS[nextIdx];
Expand Down

0 comments on commit b407125

Please sign in to comment.