Skip to content

Commit

Permalink
fix(textarea.tsx): fixed the bug where textarea with maxlength can't …
Browse files Browse the repository at this point in the history
…input before limit

用户提出issue,反馈设置maxlength后,windows自带输入法,当输入中文时所输入字符还没有达到最大长度也会没法输入.
  • Loading branch information
azx1573 committed Jan 17, 2024
1 parent 38e044a commit 0dd4ab3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,21 @@ export default mixins(Vue as VueConstructor<Textarea>, classPrefixMixins).extend
inputValueChangeHandle(e: InputEvent) {
const { target } = e;
let val = (target as HTMLInputElement).value;
if (this.maxlength) {
val = limitUnicodeMaxLength(val, Number(this.maxlength));
}
if (this.maxcharacter && this.maxcharacter >= 0) {
const stringInfo = getCharacterLength(val, this.maxcharacter);
val = typeof stringInfo === 'object' && stringInfo.characters;
if (!this.isComposing) {
if (this.maxlength) {
val = limitUnicodeMaxLength(val, Number(this.maxlength));
}
if (this.maxcharacter && this.maxcharacter >= 0) {
const stringInfo = getCharacterLength(val, this.maxcharacter);
val = typeof stringInfo === 'object' && stringInfo.characters;
}
}

this.$emit('input', val);
// 中文输入时不触发 onChange
!this.isComposing && this.emitEvent('change', val, { e });
// 中文输入结束才触发 onChange
if (!this.isComposing) {
this.emitEvent('change', val, { e });
}

this.$nextTick(() => this.setInputValue(val));
this.adjustTextareaHeight();
Expand Down

0 comments on commit 0dd4ab3

Please sign in to comment.