Skip to content

Commit

Permalink
feat(textarea): 响应式地触发 autosize 样式计算 (#1175)
Browse files Browse the repository at this point in the history
* feat(textarea): 响应式地触发 autosize 样式计算

* refactor(textarea):  autosize 样式计算逻辑
  • Loading branch information
QuentinHsu authored Dec 8, 2023
1 parent e1579a6 commit 4c85efd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/textarea/textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default defineComponent({
const textareaLength = ref(0);
const { value, modelValue } = toRefs(props);
const [innerValue, setInnerValue] = useVModel(value, modelValue, props.defaultValue, props.onChange);
const textareaClass = computed(() => [
`${componentName}`,
{
Expand Down Expand Up @@ -85,6 +84,8 @@ export default defineComponent({
const adjustTextareaHeight = () => {
if (props.autosize === true) {
textareaStyle.value = calcTextareaHeight(textareaRef.value as HTMLTextAreaElement);
} else if (props.autosize === false) {
textareaStyle.value = calcTextareaHeight(textareaRef.value as HTMLTextAreaElement, 1, 1);
} else if (typeof props.autosize === 'object') {
const { minRows, maxRows } = props.autosize;
textareaStyle.value = calcTextareaHeight(textareaRef.value as HTMLTextAreaElement, minRows, maxRows);
Expand Down Expand Up @@ -144,6 +145,12 @@ export default defineComponent({
adjustTextareaHeight();
});
});
watch(
() => props.autosize,
() => {
adjustTextareaHeight();
},
);
return {
componentName,
...toRefs(props),
Expand Down

0 comments on commit 4c85efd

Please sign in to comment.