feat(a11y): add Esc key functionality to close modal
This commit is contained in:
parent
47324f15bf
commit
bf79893dfa
@ -93,6 +93,17 @@ export default function GenerateInput({
|
||||
}
|
||||
}, [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 (
|
||||
<div className="w-full pr-4 space-y-2">
|
||||
<div className="flex items-center font-sans space-x-2">
|
||||
|
Loading…
x
Reference in New Issue
Block a user