Skip to content

Commit

Permalink
fix: numpad input on IE.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggovan authored and chrisprice committed Jul 14, 2017
1 parent 011fcff commit aac7ada
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/finput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions src/keyHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {

/**
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit aac7ada

Please sign in to comment.