arthurtyukayev / use-keyboard-shortcut Goto Github PK
View Code? Open in Web Editor NEWA custom hook that allows adding keyboard shortcuts to React applications
Home Page: https://use-keyboard-shortcut.tyukayev.com/
License: MIT License
A custom hook that allows adding keyboard shortcuts to React applications
Home Page: https://use-keyboard-shortcut.tyukayev.com/
License: MIT License
./src/utils/useKeyboardShortcut.js
Line 95:6: React Hook useEffect has a missing dependency: 'initalKeyMapping'. Either include it or remove the dependency array
react-hooks/exhaustive-deps
Line 100:6: React Hook useEffect has missing dependencies: 'keydownListener' and 'shortcutKeys'. Either include them or remove the dependency array react-hooks/exhaustive-deps
Line 105:6: React Hook useEffect has missing dependencies: 'keyupListener' and 'shortcutKeys'. Either include them or remove the dependency array react-hooks/exhaustive-deps
i get these errors when i include useKeyboardShortcut.js - a proper way to remove them?
Allow users to assign custom shortcuts that will replace those defined by browsers (such as CTRL+F)
Possibily by using event.preventDefault()
The peerDependencies
in package.json currently say this:
use-keyboard-shortcut/package.json
Lines 15 to 16 in 59b9c41
In other words, only versions higher than 16.8.0, as long as the major version is still 16. React 17 has been out for quite a while though.
tried this
useKeyboardShortcut(['kVK_Control', 'C'], () => handleSave(), { overrideSystem: true })
and
useKeyboardShortcut(['kVK_Command', 'C'], () => handleSave(), { overrideSystem: true })
Hi,
I'm using everyday the library, I just find something missing, the typescript types ;)
Hava a nice day and be happy ! ๐ฆ
just a heads up that I think you accidentally deleted the code for the hook itself in lib/
When i define two shortcuts like
useKeyboardShortcut(['Control', 'A'], () => doSomethingA());
useKeyboardShortcut(['Control', 'B'], () => doSomethingB());
I can use both Shortcuts, but only doSomethingB() is called.
I am facing issue in Contol + T short cut as it is opeing new tab, though i had already passed the option for system override true
There is a known issue causing components with multiple hook calls that include modifier keys to malfunction.
If you have 2 or more hooks with META + S and META + A, it will malfunction after the first invocation.
I'm reviewing and debugging this now.
The keyboard event's key attribute is case sensitive. All references should be lowercase to avoid issues with shift keys.
We have a modal component shown up after a shortkeys combination, this modal component will set focus on a textarea after being rendered what disallows the keyupListener to dispatch a setKeys
action.
Please, correct me if I am wrong but I think blacklistedTargets
should not be checked on the keyupListener
.
Tested on Chrome, Firefox, and Edge with both my own code and your example. Using shortcuts work fine until a browser managed shortcut like Ctrl + P is used. They then stop working until the page is reloaded.
To reproduce on the example page:
I'm trying to use a 'Shift + f' key combination to trigger a callback. It works as desired the first time. However, after that the callback gets triggered on pressing either key. It doesn't wait for the combination.
Resetting the reducer's state after a successful callback solves the problem.
Having used v. 1..0.6 for a while I recently tried updating to the latest version (which fixes another error).
It seems that since v. 1.1.0 Meta + F only works the first time. The second time it goes to the system default "search page".
useKeyboardShortcut(['Meta', 'F'], () => handleOpen(), {
overrideSystem: true,
});
Using React 16.14.0
Thanks!
When I add something like
const shortcutUndo = ['Control', 'Z']; useKeyboardShortcut(shortcutUndo, handleUndoShortcut);
and I press ctrl+shift+z or ctrl+y+z it still works.
Does anyone have an idea on how to prevent this?
Is it possible to stop event triggering if i'm editing an editable div? The triggers work perfectly fine, and don't work in input elements which is expected but trigger if I'm editing an editable div. Is there a way to avoid that? Thanks
The key handler eats character keys used in a shortcut even when the modifier is not pressed.
Eg: if I define CTRL+S as shortcut I can't type 's' in any input anymore.
Repro:
Expected result:
I'd expect the combination shortcuts don't block normal single character input.
Can't perform a React state update on an unmounted component.
error shown in console after component unmounted
I created pull request that fix this problem #27
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.