Skip to content

Commit

Permalink
Add alternative to deprecated keyCodes
Browse files Browse the repository at this point in the history
The keyCode event property has been deprecated. See the MDN link for
a description of how the new standard for key identifiers should be used.
  • Loading branch information
bjacobel committed Apr 10, 2017
1 parent cda7161 commit 8726dac
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/js/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@
/**
* Reusable constants.
*
* ### keyCodes - A mapping of key names to their corresponding codes.
* ### keys - A mapping of key names to their corresponding identifiers.
* ### keyCodes - A mapping of key names to their corresponding keyCodes (DEPRECATED).
*
* - `constants.keyCodes.tab` - the tab key
* - `constants.keyCodes.enter` - the enter key
* - `constants.keyCodes.esc` - the escape key
* - `constants.keyCodes.space` - the space key
* - `constants.keyCodes.left` - the left arrow key
* - `constants.keyCodes.up` - the up arrow key
* - `constants.keyCodes.right` - the right arrow key
* - `constants.keyCodes.down` - the down arrow key
* - `constants.keys.tab` - the tab key
* - `constants.keys.enter` - the enter key
* - `constants.keys.esc` - the escape key
* - `constants.keys.space` - the space key
* - `constants.keys.left` - the left arrow key
* - `constants.keys.up` - the up arrow key
* - `constants.keys.right` - the right arrow key
* - `constants.keys.down` - the down arrow key
*
* @class constants
*/
return {
keys: {
tab: 'Tab',
enter: 'Enter',
esc: 'Escape',
space: 'Space',
left: 'ArrowLeft',
up: 'ArrowUp',
right: 'ArrowRight',
down: 'ArrowDown'
},
// NOTE: keyCode is deprecated. Use the `key` or `code` event property if possible.
// See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
keyCodes: {
tab: 9,
enter: 13,
Expand Down

0 comments on commit 8726dac

Please sign in to comment.