react-simple-hook-modal
react-simple-hook-modal copied to clipboard
Add ability to close modal with ESC key
This would be a useful addition to help move around the UI with just the keyboard.
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);
});
@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.