mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-22 01:29:39 +08:00
Avoid cursor position change when maxLength is set
This commit is contained in:
parent
9633c99dad
commit
0c773151c7
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-keyboard",
|
"name": "simple-keyboard",
|
||||||
"version": "2.5.1",
|
"version": "2.5.2",
|
||||||
"description": "On-screen Javascript Virtual Keyboard",
|
"description": "On-screen Javascript Virtual Keyboard",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -15,7 +15,8 @@ class App {
|
|||||||
onChange: input => this.onChange(input),
|
onChange: input => this.onChange(input),
|
||||||
onKeyPress: button => this.onKeyPress(button),
|
onKeyPress: button => this.onKeyPress(button),
|
||||||
newLineOnEnter: true,
|
newLineOnEnter: true,
|
||||||
physicalKeyboardHighlight: true
|
physicalKeyboardHighlight: true,
|
||||||
|
maxLength: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,9 +195,12 @@ class Utilities {
|
|||||||
output = [source.slice(0, position), string, source.slice(position)].join('');
|
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;
|
return output;
|
||||||
@ -262,8 +265,10 @@ class Utilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(condition){
|
if(condition){
|
||||||
|
this.maxLengthReached = true;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
this.maxLengthReached = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,13 +281,19 @@ class Utilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(condition){
|
if(condition){
|
||||||
|
this.maxLengthReached = true;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
this.maxLengthReached = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMaxLengthReached = () => {
|
||||||
|
return Boolean(this.maxLengthReached);
|
||||||
|
}
|
||||||
|
|
||||||
camelCase = (string) => {
|
camelCase = (string) => {
|
||||||
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
|
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user