From a34ee4c936ff931e912343bc11cfa35526e1c932 Mon Sep 17 00:00:00 2001 From: "Y." Date: Sat, 12 Oct 2024 12:29:33 +0800 Subject: [PATCH] fix(Textarea): fix indicator not updating (#1615) --- src/textarea/textarea.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/textarea/textarea.tsx b/src/textarea/textarea.tsx index 52f34099c..3e2c980f3 100644 --- a/src/textarea/textarea.tsx +++ b/src/textarea/textarea.tsx @@ -36,7 +36,6 @@ export default defineComponent({ const textareaRef = ref(); const textareaStyle = ref(); - const textareaLength = ref(0); const { value, modelValue } = toRefs(props); const [innerValue, setInnerValue] = useVModel(value, modelValue, props.defaultValue, props.onChange); @@ -80,20 +79,26 @@ export default defineComponent({ props.maxcharacter > 0 && !Number.isNaN(props.maxcharacter) ) { - const { length = 0, characters = '' } = getCharacterLength(textarea.value, props.maxcharacter) as { + const { characters = '' } = getCharacterLength(textarea.value, props.maxcharacter) as { length: number; characters: string; }; setInnerValue(characters); - textareaLength.value = length; } else { setInnerValue(textarea.value); - textareaLength.value = textarea.value.length; } nextTick(() => setInputValue(innerValue.value)); adjustTextareaHeight(); }; + const textareaLength = computed(() => { + const _value = innerValue.value ? String(innerValue.value) : ''; + if (props.maxcharacter) { + return getCharacterLength(_value); + } + return _value.length; + }); + const handleCompositionend = (e: InputEvent | CompositionEvent) => { textareaValueChangeHandle(); };