Skip to content

Commit

Permalink
Merge pull request #269 from near/SQAC-135/close-modal-esc
Browse files Browse the repository at this point in the history
chore: Close Modal by Pressing the ESC Key
  • Loading branch information
kujtimprenkuSQA authored Apr 21, 2022
2 parents ad9348a + 2868090 commit e9c6562
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/lib/modal/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export const Modal: React.FC<ModalProps> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
const close = (e: KeyboardEvent) => {
if (e.key === "Escape") {
handleDismissClick();
}
};
window.addEventListener("keydown", close);
return () => window.removeEventListener("keydown", close);
}, []);

const handleDismissClick = () => {
if (isLoading) {
return;
Expand Down

0 comments on commit e9c6562

Please sign in to comment.