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

Interaction with other uses of Esc #14

Open
joshkel opened this issue Apr 8, 2016 · 2 comments
Open

Interaction with other uses of Esc #14

joshkel opened this issue Apr 8, 2016 · 2 comments

Comments

@joshkel
Copy link

joshkel commented Apr 8, 2016

I'm using react-modal2 as part of a more complex app that does its own keyboard handling, and I noticed that it doesn't do anything to keep its Esc event from also being seen by other parts of the site. (In my example, I have an Esc handler on my app container, and pressing Esc to close the modal also fires the app's event.)

Possible solutions:

  1. Pass useCapture true to document.addEventListener and document.removeEventListener so that react-modal2's global Esc handler fires before any individual React components'.
  2. Move the keyboard handler to the ref="modal" component; since it captures the focus, it should see any Esc keypresses.

And whether 1 or 2 is chosen, update handleDocumentKeydown to call event.stopImmediatePropagation().

I'm not an expert on DOM events, so I don't know which is better. (2 seems cleaner, but I assume there was some reason for going with document-level events in the current implementation.)

@joshkel
Copy link
Author

joshkel commented Jul 11, 2016

I put together a demo of this issue at https://github.com/joshkel/react-modal2-esc-demo. If you click the button to show the modal then press Esc to close it, it shows the parent container's "You pressed Escape" message.

@srph
Copy link

srph commented Aug 8, 2017

For now, all I've done is check state.

<Dropdown onOpen={() => this.setState({ dropdown: true })} />
<ReactModal2 closeOnEsc={!this.state.dropdown} />

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

2 participants