Avoid cursor position change when maxLength is set

This commit is contained in:
Francisco Hodge
2018-10-06 13:35:33 -04:00
parent 9633c99dad
commit 0c773151c7
3 changed files with 16 additions and 4 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ class App {
onChange: input => this.onChange(input),
onKeyPress: button => this.onKeyPress(button),
newLineOnEnter: true,
physicalKeyboardHighlight: true
physicalKeyboardHighlight: true,
maxLength: 5
});
/**
+13 -2
View File
@@ -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));
};