Skip to content

Commit

Permalink
add getNumberFromCode to support number keys, #1053
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 6, 2021
1 parent 960fd8e commit 7f759c0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion js/accessibility/KeyboardUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ const KeyboardUtils = {
return KeyboardUtils.isAnyKeyEvent( domEvent, NUMBER_KEYS );
},

/**
* For number keys, return the number of the key, or null if not a number
* @param {Event} domEvent
* @returns {null|number}
*/
getNumberFromCode( domEvent ) {
if ( KeyboardUtils.isNumberKey( domEvent ) ) {
return Number( domEvent.code.replace( 'Digit', '' ) );
}
return null;
},

/**
* Event.code distinguishes between left and right shift keys. If all you care about is the presence
* of a shift key you can use this.
Expand Down Expand Up @@ -216,7 +228,7 @@ const KeyboardUtils = {
*
* @param {Event} domEvent
* @param {string[]} keyboardUtilsKeys
* @returns {*}
* @returns {boolean}
*/
isAnyKeyEvent( domEvent, keyboardUtilsKeys ) {
validate( domEvent, DOM_EVENT_VALIDATOR );
Expand Down

0 comments on commit 7f759c0

Please sign in to comment.