Created
February 8, 2023 13:54
-
-
Save stephane-vanraes/2e07709c60019619eee9955dffed148b to your computer and use it in GitHub Desktop.
keyboard shortcut action
This file contains hidden or 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 default (button : HTMLButtonElement, key: string)=> { | |
function fn(ev: KeyboardEvent) { | |
if (ev.key == key && (ev.metaKey || ev.ctrlKey)) { | |
ev.preventDefault(); | |
button.click(); | |
} | |
} | |
window.addEventListener('keydown', fn) | |
return { | |
destroy() { window.removeEventListener('keydown', fn) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment