Giter Site home page Giter Site logo

arthurtyukayev / use-keyboard-shortcut Goto Github PK

View Code? Open in Web Editor NEW
53.0 53.0 25.0 952 KB

A custom hook that allows adding keyboard shortcuts to React applications

Home Page: https://use-keyboard-shortcut.tyukayev.com/

License: MIT License

JavaScript 100.00%
browser hooks javascript keyboard keyboard-shortcuts react reactjs shortcuts

use-keyboard-shortcut's People

Contributors

arthurtyukayev avatar dependabot[bot] avatar ismailshak avatar preet-sidhu avatar slobo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

use-keyboard-shortcut's Issues

react-hooks/exhaustive-deps

./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?

Override default keyboard shortcuts

Allow users to assign custom shortcuts that will replace those defined by browsers (such as CTRL+F)

Possibily by using event.preventDefault()

Control/command doesnt work on mac

tried this

  useKeyboardShortcut(['kVK_Control', 'C'], () => handleSave(), { overrideSystem: true })
and
  useKeyboardShortcut(['kVK_Command', 'C'], () => handleSave(), { overrideSystem: true })

Add typescript types to library

Hi,

I'm using everyday the library, I just find something missing, the typescript types ;)

Hava a nice day and be happy ! ๐Ÿฆ„

on Control+T

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

Modifier Key Bugs

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.

key up event not triggered because target is blacklisted

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 blacklistedTargetsshould not be checked on the keyupListener.

Shortcuts stop working once a browser shortcut has been used

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:

  • Mash Ctrl + F a few times, underlining works as expected
  • Use a shortcut that isn't handled by the react app (E.g. Ctrl + P)
  • Try to use Ctrl + F again, it doesn't do anything (the browser doesn't even handle it).

State needs to be reset after a successful callback.

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.

Meta + F only works the first time

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!

Avoiding keypress events in editable divs

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

Hook blocks characters used in a combination-shortcut from every input field

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:

  • Open a page with this hook and a key combination shortcut, like CTRL+S or CTRL+A, and an input field.
  • For example use the online demo from the manual and use your browsers developer inspector to add an input element.
  • Try typing in the input field. All characters work except ones used in one of the shortcuts (eg: 'a' or 's' in the demo)

Expected result:

I'd expect the combination shortcuts don't block normal single character input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.