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
react-hotkeys-hook
React hook for handling keyboard shortcuts
react-hotkeys
A declarative library for handling hotkeys and focus within a React application
hotkeys-js
A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
react-hot-keys
React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
npm install @reecelucas/react-use-hotkeys
86.2
Supply Chain
99
Quality
75.7
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
116 Stars
81 Commits
8 Forks
1 Watching
11 Branches
2 Contributors
Updated on 21 Aug 2024
TypeScript (96.56%)
JavaScript (2.52%)
Shell (0.91%)
Cumulative downloads
Total Downloads
Last day
23.1%
2,070
Compared to previous day
Last week
4.1%
9,955
Compared to previous week
Last month
-1.3%
42,701
Compared to previous month
Last year
14.2%
466,145
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 dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/15 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
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
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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