| Feb | MAR | Apr |
| 31 | ||
| 2020 | 2021 | 2022 |
COLLECTED BY
Collection: github.com
data-hotkey
attribute, but this can be overridden by passing the hotkey to the registering
function (install) as a parameter.
Multiple hotkeys are separated by a ,; key combinations are separated
by a +; and key sequences are separated by a space.
Two-keypress sequences such as g c and g i are stored
under the 'g' key in a nested object with 'c' and 'i' keys.
mappings =
'c' : <a href="/rails/rails/issues/new" data-hotkey="c">New Issue</a>
'g' :
'c' : <a href="/rails/rails" data-hotkey="g c">Code</a>
'i' : <a href="/rails/rails/issues" data-hotkey="g i">Issues</a>
In this example, both g c and ccould be available as hotkeys on the
same page, but g c and gcan't coexist. If the user presses
g, the chotkey will be unavailable for 1500 ms while we
wait for either g corg i.
$ npm install @github/hotkey
<a href="/page/2" data-hotkey="j">Next</a> <a href="/help" data-hotkey="Control+h">Help</a> <a href="/rails/rails" data-hotkey="g c">Code</a> <a href="/search" data-hotkey="s,/">Search</a>See the list of
KeyboardEvent key values for a list of supported key values.
import {install} from '@github/hotkey' // Install all the hotkeys on the page for (const el of document.querySelectorAll('[data-hotkey]')) { install(el) }Alternatively, the hotkey(s) can be passed to the
install function as a parameter e.g.:
for (const el of document.querySelectorAll('[data-shortcut]')) { install(el, el.dataset.shortcut) }To unregister a hotkey from an element, use
uninstall:
import {uninstall} from '@github/hotkey' for (const el of document.querySelectorAll('[data-hotkey]')) { uninstall(el) }
npm install
npm test