diff --git a/package.json b/package.json index ace6a8f7..a5c5686a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-keyboard", - "version": "2.5.1", + "version": "2.5.2", "description": "On-screen Javascript Virtual Keyboard", "main": "build/index.js", "scripts": { diff --git a/src/demo/App.js b/src/demo/App.js index 40f33342..89075b25 100644 --- a/src/demo/App.js +++ b/src/demo/App.js @@ -15,7 +15,8 @@ class App { onChange: input => this.onChange(input), onKeyPress: button => this.onKeyPress(button), newLineOnEnter: true, - physicalKeyboardHighlight: true + physicalKeyboardHighlight: true, + maxLength: 5 }); /** diff --git a/src/lib/services/Utilities.js b/src/lib/services/Utilities.js index cf8128b7..4a640b28 100644 --- a/src/lib/services/Utilities.js +++ b/src/lib/services/Utilities.js @@ -195,9 +195,12 @@ class Utilities { output = [source.slice(0, position), string, source.slice(position)].join(''); /** - * Update caret position + * Avoid caret position change when maxLength is set */ - this.updateCaretPos(string.length); + if(!this.isMaxLengthReached()){ + this.updateCaretPos(string.length); + } + } return output; @@ -262,8 +265,10 @@ class Utilities { } if(condition){ + this.maxLengthReached = true; return true; } else { + this.maxLengthReached = false; return false; } } @@ -276,13 +281,19 @@ class Utilities { } if(condition){ + this.maxLengthReached = true; return true; } else { + this.maxLengthReached = false; return false; } } } + isMaxLengthReached = () => { + return Boolean(this.maxLengthReached); + } + camelCase = (string) => { return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1)); };