fix(Field): incorrect maxlength slicing (#7284)

* fix(Field): incorrect maxlength slicing

* chore: robust
This commit is contained in:
neverland
2020-09-30 11:42:23 +08:00
committed by GitHub
parent f15534928e
commit 950dd10372
2 changed files with 17 additions and 4 deletions
+7 -2
View File
@@ -294,10 +294,15 @@ export default createComponent({
updateValue(value, trigger = 'onChange') {
value = isDef(value) ? String(value) : '';
// native maxlength not work when type is number
// native maxlength have incorrect line-break counting
// see: https://github.com/youzan/vant/issues/5033
const { maxlength } = this;
if (isDef(maxlength) && value.length > maxlength) {
value = value.slice(0, maxlength);
if (this.value && this.value.length === +maxlength) {
({ value } = this);
} else {
value = value.slice(0, maxlength);
}
}
if (this.type === 'number' || this.type === 'digit') {