close modals on escape key
This commit is contained in:
parent
fd36e9ef9e
commit
e76a4beb4d
|
@ -146,12 +146,24 @@ export const Modal: ModalType = ({ children, container, close }) => {
|
|||
|
||||
React.useEffect(() => {
|
||||
document.body.appendChild(el);
|
||||
|
||||
return () => {
|
||||
document.body.removeChild(el);
|
||||
};
|
||||
}, [el]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
close();
|
||||
}
|
||||
};
|
||||
document.addEventListener("keydown", handleEscape);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleEscape);
|
||||
};
|
||||
}, [close]);
|
||||
|
||||
const modal = (
|
||||
<SquiggleContainer>
|
||||
<ModalContext.Provider value={{ close }}>
|
||||
|
|
Loading…
Reference in New Issue
Block a user