theKashey / react-focus-on

🎯 Solution for WAI ARIA compatible modal dialogs or full-screen tasks, you were looking for
MIT License
336 stars 14 forks source link

onEscapeKey handler doesn't work with IE11 or some versions of Edge #10

Closed coffeedawg closed 5 years ago

coffeedawg commented 5 years ago

The following code doesn't work in IE:

var code = event.key || event.keyCode;
if ((event.code === 'Escape' || code === 'Escape' || code === 27) && _this.props.onEscapeKey) {
  _this.props.onEscapeKey(event);
}

it should be:

if ((event.code === 'Escape' || event.key === 'Escape' || event.keyCode === 27) && _this.props.onEscapeKey) {
  _this.props.onEscapeKey(event);
}

IE11 sets event.key to "Esc" so the keyCode is skipped and thereby ignored.

It seems to work correctly in Edge 18.

theKashey commented 5 years ago

Sounds correct 👍

theKashey commented 5 years ago

v3.0.5