diff --git a/src/textarea/__test__/index.test.jsx b/src/textarea/__test__/index.test.jsx
index fbc2d6caf..841b8617e 100644
--- a/src/textarea/__test__/index.test.jsx
+++ b/src/textarea/__test__/index.test.jsx
@@ -25,9 +25,10 @@ describe('Textarea.vue', () => {
const wrapper = mount(
,
);
+ expect(onChange).toBeCalledTimes(1);
const el = wrapper.find('textarea').element;
await simulateEvent(el, '一个汉字等于两个字符,超出会被剪切', 'input');
- expect(onChange).toBeCalledTimes(1);
+ expect(onChange).toBeCalledTimes(2);
expect(onChange).toHaveBeenCalledWith('一');
});
@@ -35,9 +36,10 @@ describe('Textarea.vue', () => {
const value = ref('');
const onChange = vi.fn();
const wrapper = mount();
+ expect(onChange).toBeCalledTimes(1);
const el = wrapper.find('textarea').element;
await simulateEvent(el, '这里是一段很长很长很长的长文本,支持自动换行', 'input');
- expect(onChange).toBeCalledTimes(1);
+ expect(onChange).toBeCalledTimes(2);
});
it(': placeholder', async () => {
diff --git a/src/textarea/demos/maxcharacter.vue b/src/textarea/demos/maxcharacter.vue
index 944910455..d0d49c483 100644
--- a/src/textarea/demos/maxcharacter.vue
+++ b/src/textarea/demos/maxcharacter.vue
@@ -1,11 +1,8 @@
-
+
-
+
diff --git a/src/textarea/demos/maxlength.vue b/src/textarea/demos/maxlength.vue
index 94ec5f0c1..7b610c579 100644
--- a/src/textarea/demos/maxlength.vue
+++ b/src/textarea/demos/maxlength.vue
@@ -1,11 +1,8 @@
-
+
-
+
diff --git a/src/textarea/textarea.vue b/src/textarea/textarea.vue
index 044205d25..07ada656f 100644
--- a/src/textarea/textarea.vue
+++ b/src/textarea/textarea.vue
@@ -94,34 +94,33 @@ export default defineComponent({
const handleInput = (e: any) => {
if (e.isComposing || e.inputType === 'insertCompositionText') return;
- textareaValueChangeHandle(e);
+ textareaValueChangeHandle();
};
- const textareaValueChangeHandle = (e: InputEvent) => {
- const { target } = e;
- const { value } = target as HTMLInputElement;
+ const textareaValueChangeHandle = () => {
+ const textarea = textareaRef.value as HTMLInputElement;
if (
!props.allowInputOverMax &&
props.maxcharacter &&
props.maxcharacter > 0 &&
!Number.isNaN(props.maxcharacter)
) {
- const { length = 0, characters = '' } = getCharacterLength(value, props.maxcharacter) as {
+ const { length = 0, characters = '' } = getCharacterLength(textarea.value, props.maxcharacter) as {
length: number;
characters: string;
};
setInnerValue(characters);
textareaLength.value = length;
} else {
- setInnerValue(value);
- textareaLength.value = String(innerValue.value).length;
+ setInnerValue(textarea.value);
+ textareaLength.value = String(textarea.value).length;
}
nextTick(() => setInputValue(innerValue.value));
adjustTextareaHeight();
};
const handleCompositionend = (e: InputEvent | CompositionEvent) => {
- textareaValueChangeHandle(e as InputEvent);
+ textareaValueChangeHandle();
};
const handleFocus = (e: FocusEvent) => {
@@ -135,6 +134,7 @@ export default defineComponent({
if (props.autofocus) {
textareaRef.value?.focus();
}
+ textareaValueChangeHandle();
adjustTextareaHeight();
});