Skip to content

Instantly share code, notes, and snippets.

@slavanga
Last active February 8, 2024 12:48
Show Gist options
  • Save slavanga/109b3e818ad1e14678d73d1bbf9ba4b1 to your computer and use it in GitHub Desktop.
Save slavanga/109b3e818ad1e14678d73d1bbf9ba4b1 to your computer and use it in GitHub Desktop.
Framer Override to trigger tap event when the esc key is pressed.
export function withEscTap(Component): ComponentType {
return (props) => {
const { onTap } = props
useEffect(() => {
const onKeyDown = (e) => {
if (e.key === "Escape") {
onTap()
}
}
document.addEventListener("keydown", onKeyDown)
return () => document.addEventListener("keydown", onKeyDown)
}, [])
return <Component {...props} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment