From f3a19fc85f21b8e06e2f276abf20e460fe18e4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Mon, 13 Jun 2022 15:18:06 +0200 Subject: [PATCH] [fixed] switched from KeyboardEvent.keyCode to KeyboardEvent.code KeyboardEvent.keyCode is deprecated. Since React 18 dropped support for IE, we don't need to fall back on it and can simply switch to the new property, KeyboardEvent.code. --- package-lock.json | 4 ++-- specs/helper.js | 6 +++--- src/components/ModalPortal.js | 7 ++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 401ed78e..da58db37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-modal", - "version": "3.14.4", + "version": "3.15.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1564,7 +1564,7 @@ "array-from": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", - "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", + "integrity": "sha512-GQTc6Uupx1FCavi5mPzBvVT7nEOeWMmUA9P95wpfpW1XwMSKs+KaymD5C2Up7KAUKg/mYwbsUYzdZWcoajlNZg==", "dev": true }, "array-includes": { diff --git a/specs/helper.js b/specs/helper.js index 9ff09c84..fee49570 100644 --- a/specs/helper.js +++ b/specs/helper.js @@ -182,7 +182,7 @@ const dispatchMockEvent = eventCtor => (key, code) => (element, opts) => {}, { key: key, - keyCode: code, + code: code, which: code }, opts @@ -194,11 +194,11 @@ const dispatchMockKeyDownEvent = dispatchMockEvent(Simulate.keyDown); /** * Dispatch an 'esc' key down event from an element. */ -export const escKeyDown = dispatchMockKeyDownEvent("ESC", 27); +export const escKeyDown = dispatchMockKeyDownEvent("ESC", "Escape"); /** * Dispatch a 'tab' key down event from an element. */ -export const tabKeyDown = dispatchMockKeyDownEvent("TAB", 9); +export const tabKeyDown = dispatchMockKeyDownEvent("TAB", "Tab"); /** * Dispatch a 'click' event at a node. */ diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index 8f673af1..867f756f 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -17,9 +17,6 @@ const CLASS_NAMES = { content: "ReactModal__Content" }; -const TAB_KEY = 9; -const ESC_KEY = 27; - let ariaHiddenInstances = 0; export default class ModalPortal extends Component { @@ -284,11 +281,11 @@ export default class ModalPortal extends Component { }; handleKeyDown = event => { - if (event.keyCode === TAB_KEY) { + if (event.code === "Tab") { scopeTab(this.content, event); } - if (this.props.shouldCloseOnEsc && event.keyCode === ESC_KEY) { + if (this.props.shouldCloseOnEsc && event.code === "Escape") { event.stopPropagation(); this.requestClose(event); }