From aac7ada713118334a5fcd1fbc006c3d1cba65e9a Mon Sep 17 00:00:00 2001 From: "Govan, Gordon" Date: Thu, 13 Jul 2017 17:12:19 +0100 Subject: [PATCH] fix: numpad input on IE. --- src/finput.js | 4 ++-- src/keyHandlers.js | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/finput.js b/src/finput.js index 32361f2..95c0ed7 100644 --- a/src/finput.js +++ b/src/finput.js @@ -103,11 +103,11 @@ class Finput { }, { type: ACTION_TYPES.DECIMAL, - names: [this.options.decimal] + names: [this.options.decimal, 'decimal'] }, { type: ACTION_TYPES.THOUSANDS, - names: [this.options.thousands] + names: [this.options.thousands, 'separator'] }, { type: ACTION_TYPES.SHORTCUT, diff --git a/src/keyHandlers.js b/src/keyHandlers.js index a03caf8..213a30a 100644 --- a/src/keyHandlers.js +++ b/src/keyHandlers.js @@ -7,6 +7,14 @@ import { RANGE } from './constants'; import helpers from './helpers'; +// Older browsers use these for the 'key' element of KeyboardEvents for the numpad. +const numpadKeys = [ + 'add', + 'subtract', + 'multiply', + 'divide' +]; + module.exports = { /** @@ -244,9 +252,13 @@ module.exports = { * @param {keyInfo} Information about the pressed key */ onUnknown: function (currentState, keyInfo) { - // all printable characters have a key with length of 1 - // if a character has got this far it is an invalid character - const isInvalid = keyInfo.keyName.length === 1 && !keyInfo.modifierKey; + // most printable characters have a key with length of 1, + // the numpad characters may have textual keys on older browsers + const isPrintableCharacter = keyInfo.keyName.length === 1 + || numpadKeys.indexOf(keyInfo.keyName) > -1; + + // all printable characters are invalid, unless it is a command/shortcut + const isInvalid = isPrintableCharacter && !keyInfo.modifierKey; const newState = { ...currentState }; newState.valid = !isInvalid;