Last active
February 8, 2024 12:48
-
-
Save slavanga/109b3e818ad1e14678d73d1bbf9ba4b1 to your computer and use it in GitHub Desktop.
Framer Override to trigger tap event when the esc key is pressed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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