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

Add ability to close modal with ESC key #10

Open
mbrookson opened this issue May 3, 2020 · 2 comments
Open

Add ability to close modal with ESC key #10

mbrookson opened this issue May 3, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@mbrookson
Copy link
Owner

This would be a useful addition to help move around the UI with just the keyboard.

@mbrookson mbrookson added the enhancement New feature or request label May 3, 2020
@manfromanotherland
Copy link

Maybe something like this would work?

const keyboardShortcuts = useCallback((event) => {
  if (event.keyCode === 27) {
    closeModal();
  }
}, []);

useEffect(() => {
  document.addEventListener('keydown', keyboardShortcuts);
  return () => document.removeEventListener('keydown', keyboardShortcuts);
});

@mbrookson
Copy link
Owner Author

@EdmundoJr Thanks for the suggestion! I've not tried it but it looks reasonable. Feel free to PR a change, otherwise I will try to get round to implementing this in the near future.

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

No branches or pull requests

2 participants