Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(textarea): 公共组件当初始处于隐藏状态再次可视后未做高度再计算的问题 #3003

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ export default mixins(Vue as VueConstructor<Textarea>, classPrefixMixins).extend
},
},
mounted() {
this.adjustTextareaHeight();
const textareaElem = this.$refs.refTextareaElem as HTMLInputElement;
if (textareaElem) {
textareaElem.addEventListener('transitionend', this.adjustTextareaHeight);
} else {
this.adjustTextareaHeight();
}
},

beforeDestroy() {
const textareaElem = this.$refs.refTextareaElem as HTMLInputElement;
if (textareaElem) {
textareaElem.removeEventListener('transitionend', this.adjustTextareaHeight);
}
},

watch: {
Expand All @@ -111,18 +123,20 @@ export default mixins(Vue as VueConstructor<Textarea>, classPrefixMixins).extend

methods: {
adjustTextareaHeight() {
if (!this.$refs.refTextareaElem) return;
if (this.autosize === true) {
this.textareaStyle = calcTextareaHeight(this.$refs.refTextareaElem as HTMLTextAreaElement);
} else if (this.autosize && typeof this.autosize === 'object') {
this.textareaStyle = calcTextareaHeight(
this.$refs.refTextareaElem as HTMLTextAreaElement,
this.autosize?.minRows,
this.autosize?.maxRows,
);
} else if (this.$attrs.rows) {
this.textareaStyle = { height: 'auto', minHeight: 'auto' };
}
this.$nextTick(() => {
if (!this.$refs.refTextareaElem) return;
if (this.autosize === true) {
this.textareaStyle = calcTextareaHeight(this.$refs.refTextareaElem as HTMLTextAreaElement);
} else if (this.autosize && typeof this.autosize === 'object') {
this.textareaStyle = calcTextareaHeight(
this.$refs.refTextareaElem as HTMLTextAreaElement,
this.autosize?.minRows,
this.autosize?.maxRows,
);
} else if (this.$attrs.rows) {
this.textareaStyle = { height: 'auto', minHeight: 'auto' };
}
});
},
emitEvent(name: string, value: string | number, context: object) {
this.$emit(name, value, context);
Expand Down
Loading