Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] switched from KeyboardEvent.keyCode to KeyboardEvent.code #953

Merged
merged 5 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions specs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const dispatchMockEvent = eventCtor => (key, code) => (element, opts) =>
{},
{
key: key,
keyCode: code,
code: code,
robinmetral marked this conversation as resolved.
Show resolved Hide resolved
which: code
diasbruno marked this conversation as resolved.
Show resolved Hide resolved
},
opts
Expand All @@ -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");
diasbruno marked this conversation as resolved.
Show resolved Hide resolved
/**
* Dispatch a 'click' event at a node.
*/
Expand Down
7 changes: 2 additions & 5 deletions src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -274,11 +271,11 @@ export default class ModalPortal extends Component {
};

handleKeyDown = event => {
if (event.keyCode === TAB_KEY) {
robinmetral marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Expand Down