diff --git a/src/components/cc-input-number/cc-input-number.js b/src/components/cc-input-number/cc-input-number.js index a2528593e..d9cad80ac 100644 --- a/src/components/cc-input-number/cc-input-number.js +++ b/src/components/cc-input-number/cc-input-number.js @@ -17,6 +17,7 @@ import '../cc-icon/cc-icon.js'; * @typedef {import('lit/directives/ref.js').Ref} HTMLInputElementRef * @typedef {import('lit/directives/ref.js').Ref} HTMLElementRef * @typedef {import('../../lib/events.types.js').EventWithTarget} HTMLInputElementEvent + * @typedef {import('../../lib/events.types.js').GenericEventWithTarget} 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 @@ -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'); } diff --git a/src/stories/lib/i18n-control.js b/src/stories/lib/i18n-control.js index 8448dcdaa..c859b38cb 100644 --- a/src/stories/lib/i18n-control.js +++ b/src/stories/lib/i18n-control.js @@ -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];