feat(a11y): add Esc key functionality to close modal

This commit is contained in:
Hamzat Victor 2024-09-05 13:30:41 +01:00
parent 47324f15bf
commit bf79893dfa

View File

@ -93,6 +93,17 @@ export default function GenerateInput({
} }
}, [code]) }, [code])
useEffect(() => {
//listen to when Esc key is pressed and close the modal
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "Escape") {
onClose()
}
}
window.addEventListener("keydown", handleKeyDown)
return () => window.removeEventListener("keydown", handleKeyDown)
}, [])
return ( return (
<div className="w-full pr-4 space-y-2"> <div className="w-full pr-4 space-y-2">
<div className="flex items-center font-sans space-x-2"> <div className="flex items-center font-sans space-x-2">