react-keybinding-component
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

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.

Property Description Default value
onKey (required) the function executed after a key event n/a
type keyup or keydown 'keydown'
target the 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
preventInputConflict prevent onKey from firing if you have an onChange on an input, a textarea or a select false
preventContentEditableConflict prevent onKey from firing if the user is editing the DOM via contenteditable="true", usually used by WYSIWYG editors false
preventDefault prevent event default false
preventPropagation prevent event propagation false

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.2.071latest

Version History

VersionDownloads (Last 7 Days)Published
2.2.071
2.0.21
2.0.10
2.0.01
1.0.01,466
0.5.2370
0.5.11,274
0.5.00
0.4.10
0.4.01
0.3.20
0.3.10
0.3.00
0.2.10
0.2.00
0.1.10
0.1.00

Package Sidebar

Install

npm i react-keybinding-component

Weekly Downloads

3,184

Version

2.2.0

License

MIT

Unpacked Size

19.2 kB

Total Files

9

Last publish

Collaborators

  • martpie