github / hotkey

Trigger an action on an element with a keyboard shortcut.
https://github.github.com/hotkey/
MIT License
3.22k stars 97 forks source link

Don't mandate the use of the `data-hotkey` attribute #7

Closed chocolateboy closed 5 years ago

chocolateboy commented 5 years ago

Allow the hotkey to be passed to the registering function (install) as an optional parameter, rather than requiring the use of the data-hotkey attribute. And update and expand the documentation (closes #5).

koddsson commented 5 years ago

Hey @chocolateboy and thanks for the PR ✨

I'm wondering what the benefit of denoting the hotkey as a JS variable over keeping it as-is on the element as a attribute?

chocolateboy commented 5 years ago

This PR doesn't remove the data attribute. It's still available as the default/fallback way to define hotkeys. The optional parameter just provides more flexibility.

On a custom element or in a framework we might want to use, say, hotkey rather than data-hotkey. Or (data-)hotkeys since there can be more than one. Or perhaps we're already using data-hotkey for something else and don't want to change it. Or we want to assign hotkeys programatically per element ID or class. This PR adds the option to do so rather than forcing all users to comply with a hardwired API.

mislav commented 5 years ago

Thank you!