Add keyboard motion for modal
This commit is contained in:
parent
130157af51
commit
3b275e723d
|
@ -89,6 +89,20 @@ export function Modal({
|
||||||
setTimeout(onClose, 250);
|
setTimeout(onClose, 250);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKeyPress = (event: Event) => {
|
||||||
|
const e = event as KeyboardEvent;
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setInternalOpen(false);
|
||||||
|
setTimeout(onClose, 250);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("keydown", onKeyPress);
|
||||||
|
|
||||||
|
return () => document.removeEventListener("keydown", onKeyPress);
|
||||||
|
}, [setInternalOpen, onClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className={classnames(
|
||||||
|
|
Loading…
Reference in New Issue