Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@github/hotkey

Package Overview
Dependencies
Maintainers
14
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/hotkey - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

6

dist/index.esm.js

@@ -243,4 +243,4 @@ function _classCallCheck(instance, Constructor) {

});
function install(element) {
var hotkeys = expandHotkeyToEdges(element.getAttribute('data-hotkey') || '');
function install(element, hotkey$$1) {
var hotkeys = expandHotkeyToEdges(hotkey$$1 || element.getAttribute('data-hotkey') || '');
var leaves = hotkeys.map(function (hotkey$$1) {

@@ -281,2 +281,2 @@ return hotkeyRadixTrie.insert(hotkey$$1).add(element);

export { install, uninstall };
export { RadixTrie, Leaf, install, uninstall };

@@ -249,4 +249,4 @@ (function (global, factory) {

});
function install(element) {
var hotkeys = expandHotkeyToEdges(element.getAttribute('data-hotkey') || '');
function install(element, hotkey$$1) {
var hotkeys = expandHotkeyToEdges(hotkey$$1 || element.getAttribute('data-hotkey') || '');
var leaves = hotkeys.map(function (hotkey$$1) {

@@ -287,2 +287,4 @@ return hotkeyRadixTrie.insert(hotkey$$1).add(element);

exports.RadixTrie = RadixTrie;
exports.Leaf = Leaf;
exports.install = install;

@@ -289,0 +291,0 @@ exports.uninstall = uninstall;

{
"name": "@github/hotkey",
"version": "1.0.4",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.umd.js",

# Hotkey Behavior
Trigger a action on element when keyboard hotkey is pressed.
Trigger an action on a target element when a key or sequence of keys is pressed
on the keyboard. This triggers a focus event on form fields, or a click event on
`<a href="...">`, `<button>` and `<summary>` elements.
Automatically binds hotkeys to any link with a `data-hotkey`
attribute set. Multiple hotkeys are separated by a `,`.
Key combinations are separated by a `+`, and key sequences
are separated by a space.
By default, hotkeys are extracted from a target element's `data-hotkey`
attribute, but this can be overridden by passing the hotkey to the registering
function (`install`) as a parameter.
Two-keypress sequences like `g c` and `g i` would be stored
under the 'g' key in a nested object with keys 'c' and 'i'.
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.
```

@@ -21,7 +25,17 @@ mappings =

So both `g c` and `c` could be available hotkeys on the same
page, but `g c` and `g` couldn't coexist. If the user presses
`g`, the `c` hotkey will be unavailable for 1500ms while we
listen for either `g c` or `g i`.
In this example, both `g c` and `c` could be available as hotkeys on the
same page, but `g c` and `g` can't coexist. If the user presses
`g`, the `c` hotkey will be unavailable for 1500 ms while we
wait for either `g c` or `g i`.
## Accessibility considerations
Please note that adding this functionality to your site can be a drawback for
certain users. Providing a way in your system to disable hotkeys or remap
them makes sure that those users can still use your site (given that it's
accessible to those users).
See ["Understanding Success Criterion 2.1.4: Character Key Shortcuts"](https://www.w3.org/WAI/WCAG21/Understanding/character-key-shortcuts.html)
for further reading on this topic.
## Installation

@@ -50,3 +64,4 @@

import {install} from '@github/hotkey'
for (const el of document.querySelector('[data-hotkey]')) {
for (const el of document.querySelectorAll('[data-hotkey]')) {
install(el)

@@ -56,2 +71,20 @@ }

Alternatively, the hotkey(s) can be passed to the `install` function as a parameter e.g.:
```js
for (const el of document.querySelectorAll('[data-shortcut]')) {
install(el, el.dataset.shortcut)
}
```
To unregister a hotkey from an element, use `uninstall`:
```js
import {uninstall} from '@github/hotkey'
for (const el of document.querySelectorAll('[data-hotkey]')) {
uninstall(el)
}
```
## Development

@@ -58,0 +91,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc