question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pressing enter key to close button closes the modal but the event is attached to opener element and reopens the modal

See original GitHub issue

Summary:

Steps to reproduce:

  1. Visit my demo on Codesandbox https://codesandbox.io/s/react-modal-vivyxc?file=/src/index.js
  2. Click ‘Open Modal’ button and press Tab. This will focus the close button
  3. Press Enter this closes the modal but reopens it. I know this is because of the onKeyUp event listener to anchor tag but this function is needed for other purposes.

Expected behavior:

Closes modal and focus move to the opener element( in this case, anchor tag)

Link to example of issue:

Codesandbox https://codesandbox.io/s/react-modal-vivyxc?file=/src/index.js

Additional notes:

Is there a way to solve this issue without removing the onKeyUp event handler?

Thanks.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
diasbrunocommented, Jun 19, 2022

Try comby. It’s simple and amazing refactoring tool.

0reactions
brainsaysnocommented, Jun 20, 2022

Your issue seems to be specific to your project rather than being a package issue. +1 on refactoring to make your events onKeyDown. That solves it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pressing enter key to close button closes my modal but the ...
The problem is when I close the modal with tab and enter key, the key event is also attached to the opener onKeyUp...
Read more >
Solved: Bootstrap modal closing while press ENTER key in t...
I have an SP modal widget which contain textarea element, in this field the user should have the ability to break-line by press...
Read more >
Modal button is not clicked when pressing Enter key
At the moment, after open modal and pressing the enter key, nothing happens. Only when the button is focused, pressing enter works. You...
Read more >
Reveal | Foundation for Sites 6 Docs
You'll also need a way to close the modal from inside. By default, modals will close if clicked outside of, or if the...
Read more >
Using modals in Slack apps
push , or in response_action s, as shown below. If a user closes a specific view in a modal using the Cancel button,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found