ember-keyboard-shortcuts
Compatibility
- Ember.js v2.18 or above
- Ember CLI v2.13 or above
Installation
In your ember-cli project:
ember install ember-keyboard-shortcuts
Usage
We expose two functions to setup and remove keyboard shortcuts. You can use it in routes, components or controllers.
In a route
;;;
In a component
;; ;
Available shortcut options
action
: action to trigger. Can be a function or a string containing action name.global
: indicates whether events should be triggered withininput
,textarea
andselect
. Default:true
.scoped
: indicates that the shortcuts should only be registered for the current component/view and its children. Impliesglobal: true
. Default:false
.preventDefault
: prevents the default action and stops the event from bubbling up. Applies only when theaction
is a string. Default:true
.
Testing
You will want to use the triggerKeyEvent helper from ember-test-helpers. We listen for the keydown
event by default. You must always scope the trigger in your tests to at least a child element of the scoping option you pass.
// Setting `global: false,`await ; // Setting `scoped: true,`await ; // Passing `targetElement: <element>,`await ; // Default behaviorawait ;
Migrating from mixins
Prior versions, you could use this addon with mixins. We have deprecated that behavior in order to calling specific functions to setup shortcuts as well to destroy event listeners.
Here is an example of not using mixins in a route.
;; Route;
In summary, if you used to use ember-keyboard-shortcuts
in routes, you will
add a function call activate
and deactivate
.
To migrate from a components or a view, you should use didInsertElement
and
willDestroyElement
hooks.
Development
See the Contributing guide for details.
For more information on using ember-cli, visit http://www.ember-cli.com/.