Pressing enter key to close button closes the modal but the event is attached to opener element and reopens the modal
See original GitHub issueSummary:
Steps to reproduce:
- Visit my demo on Codesandbox https://codesandbox.io/s/react-modal-vivyxc?file=/src/index.js
- Click ‘Open Modal’ button and press
Tab
. This will focus the close button - Press
Enter
this closes the modal but reopens it. I know this is because of theonKeyUp
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:
- Created a year ago
- Comments:7
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try comby. It’s simple and amazing refactoring tool.
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.