Skip to content

Commit f3a19fc

Browse files
Robin Métraldiasbruno
Robin Métral
authored andcommitted
[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.
1 parent aca5261 commit f3a19fc

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: specs/helper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const dispatchMockEvent = eventCtor => (key, code) => (element, opts) =>
182182
{},
183183
{
184184
key: key,
185-
keyCode: code,
185+
code: code,
186186
which: code
187187
},
188188
opts
@@ -194,11 +194,11 @@ const dispatchMockKeyDownEvent = dispatchMockEvent(Simulate.keyDown);
194194
/**
195195
* Dispatch an 'esc' key down event from an element.
196196
*/
197-
export const escKeyDown = dispatchMockKeyDownEvent("ESC", 27);
197+
export const escKeyDown = dispatchMockKeyDownEvent("ESC", "Escape");
198198
/**
199199
* Dispatch a 'tab' key down event from an element.
200200
*/
201-
export const tabKeyDown = dispatchMockKeyDownEvent("TAB", 9);
201+
export const tabKeyDown = dispatchMockKeyDownEvent("TAB", "Tab");
202202
/**
203203
* Dispatch a 'click' event at a node.
204204
*/

Diff for: src/components/ModalPortal.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const CLASS_NAMES = {
1717
content: "ReactModal__Content"
1818
};
1919

20-
const TAB_KEY = 9;
21-
const ESC_KEY = 27;
22-
2320
let ariaHiddenInstances = 0;
2421

2522
export default class ModalPortal extends Component {
@@ -284,11 +281,11 @@ export default class ModalPortal extends Component {
284281
};
285282

286283
handleKeyDown = event => {
287-
if (event.keyCode === TAB_KEY) {
284+
if (event.code === "Tab") {
288285
scopeTab(this.content, event);
289286
}
290287

291-
if (this.props.shouldCloseOnEsc && event.keyCode === ESC_KEY) {
288+
if (this.props.shouldCloseOnEsc && event.code === "Escape") {
292289
event.stopPropagation();
293290
this.requestClose(event);
294291
}

0 commit comments

Comments
 (0)