Skip to content

Commit

Permalink
fix(Textarea): fix indicator not updating (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao authored Oct 12, 2024
1 parent c9e6af1 commit a34ee4c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default defineComponent({

const textareaRef = ref<HTMLTextAreaElement>();
const textareaStyle = ref();
const textareaLength = ref(0);
const { value, modelValue } = toRefs(props);
const [innerValue, setInnerValue] = useVModel(value, modelValue, props.defaultValue, props.onChange);

Expand Down Expand Up @@ -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();
};
Expand Down

0 comments on commit a34ee4c

Please sign in to comment.