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

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

Open
cjpmedius opened this issue Aug 1, 2022 · 0 comments
Open

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

cjpmedius opened this issue Aug 1, 2022 · 0 comments

Comments

@cjpmedius
Copy link

cjpmedius commented Aug 1, 2022

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:

  • 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") {

This issue is related to a previous change to the same code to solve an IE11 compatibility issue:
#211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant