Skip to content

Seedstars/react-hotkey

 
 

Repository files navigation

react-hotkey

Build Status

A simple mixin for application hotkeys.

Provides a react synthetic event to the named event handler, but only when the component is mounted.

For more info, check out the demo from the example folder.

Install

npm install react-hotkey --save

react-hotkey does not declare an explicit dependency on React, but should be installed alongside it in your application. At the time of writing it has been tested with React 0.12.2

Usage

var hotkey = require('react-hotkey');
// Enable event listening, can be safely called multiple times
hotkey.activate();
// The default is to listen for 'keyup' but you can listen to others by passing an argument
hotkey.activate('keydown');


React.createClass({
    mixins: [hotkey.Mixin('handleHotkey')],
    handleHotkey: function(e) {
        // receives a React Keyboard Event
        // http://facebook.github.io/react/docs/events.html#keyboard-events
    }
})

Acknowledgements

This approach was extracted from react-bootstrap.

License

MIT

About

A simple mixin for application hotkeys

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%