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

react-key-listener

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-key-listener

React component for handling keyboard events

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-46.87%
Maintainers
1
Weekly downloads
 
Created
Source

KeyListener

React component for handling keyboard events. Use this instead of calling addEventListener or adding onKeyDown to elements manually.

Usage

Install: npm install --save react-key-listener.

Example:

class MyComponent extends React.Component {
  handleAKey = () => {
    // do something
  };

  render() {
    return (
      <div tabIndex={0 /* allow this div to be given user focus */}>
        <KeyListener keyDownHandlers={{
          a: this.handleAKey
        }} />
      </div>
    );
  }
}

KeyListener ignores key events when the event originated from an <input>, <textarea>, or contenteditable element. This prevents your key event handlers from triggering when the user expected to be typing in a text field.

The event listener is added to the KeyEvent component's parent element.

Props

NameTypeDescription
keyDownHandlers{ [key: string]: (event: KeyboardEvent) => void }event handlers for keydown events. if event.key appears as a property on this object, the corresponding handler will be called
keyPressHandlers{ [key: string]: (event: KeyboardEvent) => void }
keyUpHandlers{ [key: string]: (event: KeyboardEvent) => void }
globaltrue | falseif true, listen to events on document; if false, listen on the KeyListener's parent element

FAQs

Package last updated on 28 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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