Skip to content

Commit

Permalink
[fixed] address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Métral authored and diasbruno committed Oct 14, 2022
1 parent f3a19fc commit 15e0711
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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.

16 changes: 14 additions & 2 deletions src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const CLASS_NAMES = {
content: "ReactModal__Content"
};

/**
* We need to support the deprecated `KeyboardEvent.keyCode` in addition to
* `KeyboardEvent.code` for apps that still support IE11. Can be removed when
* `react-modal` only supports React >18 (which dropped IE support).
*/
const isTabKey = event => {
event.code === "Tab" || event.keyCode === 9;
};
const isEscKey = event => {
event.code === "Escape" || event.keyCode === 27;
};

let ariaHiddenInstances = 0;

export default class ModalPortal extends Component {
Expand Down Expand Up @@ -281,11 +293,11 @@ export default class ModalPortal extends Component {
};

handleKeyDown = event => {
if (event.code === "Tab") {
if (isTabKey(event)) {
scopeTab(this.content, event);
}

if (this.props.shouldCloseOnEsc && event.code === "Escape") {
if (this.props.shouldCloseOnEsc && isEscKey(event)) {
event.stopPropagation();
this.requestClose(event);
}
Expand Down

0 comments on commit 15e0711

Please sign in to comment.