2.0.2 • Published 10 months ago

react-keybinding-component v2.0.2

Weekly downloads
789
License
MIT
Repository
github
Last release
10 months ago

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
preventDefaultprevent event defaultfalse
preventPropagationprevent event propagationfalse
2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.0

5 years ago

0.5.2

5 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago