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

react-keybinding-component

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-keybinding-component

A React keybinding component

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
628
increased by37.12%
Maintainers
1
Weekly downloads
 
Created
Source

react-keybinding-component

A React keybinding component, usable with es6, no mixin

Description

react-keybinding-component is a component that will help you set up keybindings in your app. For the moment, only simple key events are supported (one key only, keyup, keydown). It's just a less dirty way of using key events instead of having care of them with componentDidMount() in multiple components.

Examples

Import it in your project:

import KeyBinding from 'react-keybinding-component';

Get the eventKey keyCode and log it

<KeyBinding onKey={ (e) => { console.log(e.keyCode) } } />

Get the eventKey keyCode and log it on keyUp on the window element

<KeyBinding onKey={ (e) => { console.log(e.keyCode) } } type='keyup' target={ window } />

Have a look at options.

Options

All properties except onKey are optional.

PropertyDescriptionDefault value
onKey (required)the function executed after a key eventn/a
typekeyup or keydown'keydown'
targetthe element you want to attach the event to, it can be an existing DOM element or a CSS selector (in that case, you will need to add a tabIndex='0' to your element, otherwise the event won't be caught)document
preventInputConflictprevent onKey from firing if you have an onChange on an input, a textarea or a selectfalse
preventContentEditableConflictprevent onKey from firing if the user is editing the DOM via contenteditable="true", usually used by WYSIWYG editorsfalse
preventDefaultprevent event defaultfalse
preventPropagationprevent event propagationfalse

Keywords

FAQs

Package last updated on 16 May 2024

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