0.0.1-alpha-1 • Published 6 years ago

keyhandler v0.0.1-alpha-1

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

keyhandler

Hassle-free keyboard handler to implement shortcuts in your web application.

Installation

First install it via npm or yarn
$ npm install keyhandler --save
or
$ yarn add keyhandler

then import to js modules

import Keyhandler from 'keyhandler'
// or
const Keyhandler = require('keyhandler')

it's now ready to use.

Usage

Keyhandler needs rendered elements. So it's a good practice to enqueue handlers after the entire body loaded.

Keyhandler.enqueue({
  name: 'unique-name-of-the-handler',
  elements: [input],
  shortcuts: [{
    keyCode: 83, // S key
    ctrlKey: true,
    altKey: false,
    shiftKey: false
  }],
  handler: (sender, e) => {
    // 1. prevent default behavior of the browser
    e.preventDefault()

    // 2. save the document

    // 3. stop propagating the event to next handlers in the queue
    return false
  }
})

Tests

$ npm test

Contributing

Please write unit tests for every new or changed function Don't forget to lint and test