react-bootstrap / react-overlays

Utilities for creating robust overlay components
https://react-bootstrap.github.io/react-overlays
MIT License
897 stars 222 forks source link

Use of deprecated keyCode event prop for Overlay close detection #1011

Open cjpmedius opened 2 years ago

cjpmedius commented 2 years ago

Describe the bug

The useRootClose hook relies on the deprecated keyCode event prop to trigger the escape key close behaviour.

Certain modern testing setups (such as v14 of @testing-library/user-event) no longer populate this prop, so tests of the close behaviour will fail.

To Reproduce

Steps to reproduce the behavior:

Expected behavior

onClose handler is called.

Additional Info

While I appreciate this is not a bug in some respects, since browsers still populate the keyCode prop, it should be possible to amend this code to allow for both legacy and modern compatibility.

e.g. amend line 81 of src/useRootClose.ts if (e.keyCode === escapeKeyCode) { to if ((e.keyCode && e.keyCode === escapeKeyCode) || e.key === "Escape") {

This issue is related to a previous change to the same code to solve an IE11 compatibility issue: https://github.com/react-bootstrap/react-overlays/pull/211