Gathering detailed insights and metrics for @reecelucas/react-use-hotkeys
Gathering detailed insights and metrics for @reecelucas/react-use-hotkeys
Gathering detailed insights and metrics for @reecelucas/react-use-hotkeys
Gathering detailed insights and metrics for @reecelucas/react-use-hotkeys
npm install @reecelucas/react-use-hotkeys
Typescript
Module System
Node Version
NPM Version
82.3
Supply Chain
100
Quality
75.9
Maintenance
100
Vulnerability
100
License
TypeScript (96.56%)
JavaScript (2.52%)
Shell (0.91%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,135,194
Last Day
1,329
Last Week
9,400
Last Month
40,697
Last Year
467,886
MIT License
116 Stars
81 Commits
8 Forks
1 Watchers
11 Branches
2 Contributors
Updated on Aug 21, 2024
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
@reecelucas/react-use-hotkeys@2.0.0
Unpacked Size
29.88 kB
Size
7.11 kB
File Count
47
NPM Version
8.15.0
Node Version
16.17.0
Cumulative downloads
Total Downloads
Last Day
-21.9%
1,329
Compared to previous day
Last Week
-4.9%
9,400
Compared to previous week
Last Month
33.5%
40,697
Compared to previous month
Last Year
6.9%
467,886
Compared to previous year
1
26
React hook for creating simple keyboard shortcuts.
1npm install @reecelucas/react-use-hotkeys
1import useHotkeys from "@reecelucas/react-use-hotkeys";
All hotkey combinations must use valid KeyBoardEvent
"key"
values. A full list can be found on MDN and Wes Bos has created a great interactive lookup.
1// Single keys 2useHotkeys("Escape", () => { 3 console.log("Some action"); 4}); 5 6useHotkeys("F7", () => { 7 console.log("Some action"); 8}); 9 10// Modifier combinations 11useHotkeys("Meta+Shift+z", () => { 12 console.log("Some action"); 13}); 14 15// Key sequences 16useHotkeys("w s d", () => { 17 console.log("Some action"); 18}); 19 20useHotkeys('w " " d', () => { 21 // space key in sequence (`w ' ' d` also works) 22 console.log("Some action"); 23}); 24 25// Multiple key combinations mapped to the same callback 26useHotkeys(["Control+z", "Meta+z"], () => { 27 console.log("Some action"); 28}); 29 30useHotkeys(["a", "Meta+z", "w s d"], () => { 31 console.log("Some action"); 32});
The following patterns are not supported:
1// Modifier keys in sequences 2useHotkeys("Control i d", () => { 3 console.log("I won't run!"); 4}); 5 6// Modifier combinations in sequences 7useHotkeys("Control+z i d", () => { 8 console.log("I won't run!"); 9});
If you find a use case where the API is too restrictive you can use the escape hatch to perform whatever custom logic you need:
1useHotkeys("*", (event) => { 2 console.log("I will run on every keydown event"); 3 4 if (customKeyLogic(event)) { 5 console.log("some action"); 6 } 7});
enabled
You can disable the hook by passing enabled: false
. When disabled the hook will stop listening for keydown
events:
1useHotkeys( 2 "Escape", 3 () => { 4 console.log("I won't run!"); 5 }, 6 { enabled: false } 7);
enableOnContentEditable
By default, the hook will ignore keydown
events originating from elements with the contenteditable
attribute, since this behaviour is normally what you want. If you want to override this behaviour you can pass enableOnContentEditable: true
:
1useHotkeys( 2 "Escape", 3 () => { 4 console.log("Some action"); 5 }, 6 { enableOnContentEditable: true } 7);
ignoredElementWhitelist
By default, the hook will ignore keydown
events originating from INPUT
and TEXTAREA
elements, since this behaviour is normally what you want. If you want to override this behaviour you can use ignoredElementWhitelist
:
1useHotkeys( 2 "Escape", 3 () => { 4 console.log("I will now run on input elements"); 5 }, 6 { ignoredElementWhitelist: ["INPUT"] } 7); 8 9useHotkeys( 10 "Escape", 11 () => { 12 console.log("I will now run on input and textarea elements"); 13 }, 14 { ignoredElementWhitelist: ["INPUT", "TEXTAREA"] } 15);
eventListenerOptions
You can pass AddEventListenerOptions
if you need to listen for keydown
events in the capturing phase:
1useHotkeys( 2 "Escape", 3 () => { 4 console.log("I will run in the capturing phase"); 5 }, 6 { 7 eventListenerOptions: { 8 capture: true, 9 }, 10 } 11);
1useHotkeys( 2 hotkeys: string | string[], 3 callback: (event: KeyboardEvent) => void, 4 options?: { 5 enabled?: boolean; 6 enableOnContentEditable?: boolean; 7 ignoredElementWhitelist?: ("INPUT" | "TEXTAREA")[]; 8 eventListenerOptions?: AddEventListenerOptions; 9 } 10) => void;
Tests use Jest and react-testing-library.
1git clone git@github.com:reecelucas/react-use-hotkeys.git 2cd react-use-hotkeys 3yarn 4yarn test
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/15 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
44 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More