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:
Render an Overlay control in a jest test, setting open=true, rootClose=true, and adding onHide event handler
using @testing-library/user-event, call userEvent.keyboard("{Escape}")
onHide event handler is not called.
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") {
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) {
toif ((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