mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Avoid cursor position change when maxLength is set
This commit is contained in:
+2
-1
@@ -15,7 +15,8 @@ class App {
|
||||
onChange: input => this.onChange(input),
|
||||
onKeyPress: button => this.onKeyPress(button),
|
||||
newLineOnEnter: true,
|
||||
physicalKeyboardHighlight: true
|
||||
physicalKeyboardHighlight: true,
|
||||
maxLength: 5
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user