Skip to content

Commit

Permalink
close modals when user hits Escape key (#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Mar 27, 2024
1 parent 6c3e1ac commit 6953769
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion wormhole-connect/src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeStyles } from 'tss-react/mui';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { Dialog, ScopedCssBaseline } from '@mui/material';
// import { useTheme } from '@mui/material/styles';
// import useMediaQuery from '@mui/material/useMediaQuery';
Expand Down Expand Up @@ -63,6 +63,18 @@ function Modal({ open, width, closable, children, onClose }: Props) {
event.stopPropagation();
}, []);

useEffect(() => {
const callback = (e: any) => {
if (e.keyCode === 27 || e.which === 27) onClose();
};

document.addEventListener('keyup', callback);

return () => {
document.removeEventListener('keyup', callback);
};
}, []);

return (
<Dialog
open={open}
Expand Down

0 comments on commit 6953769

Please sign in to comment.