From 1c5fac7abef28f7f794c2a55287677cafa5e5027 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 9 Dec 2020 17:03:33 +0300 Subject: [PATCH] Fixed #733 - Textarea does not auto resize its height when created --- src/components/textarea/Textarea.vue | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/components/textarea/Textarea.vue b/src/components/textarea/Textarea.vue index d5e083649e..aafe0601e1 100755 --- a/src/components/textarea/Textarea.vue +++ b/src/components/textarea/Textarea.vue @@ -9,7 +9,6 @@ export default { modelValue: null, autoResize: Boolean }, - cachedScrollHeight: null, mounted() { if (this.$el.offsetParent && this.autoResize) { this.resize(); @@ -22,24 +21,15 @@ export default { }, methods: { resize() { - if (!this.cachedScrollHeight) { - this.cachedScrollHeight = this.$el.scrollHeight; - this.$el.style.overflow = "hidden"; + this.$el.style.height = 'auto'; + this.$el.style.height = this.$el.scrollHeight + 'px'; + + if (parseFloat(this.$el.style.height) >= parseFloat(this.$el.style.maxHeight)) { + this.$el.style.overflowY = "scroll"; + this.$el.style.height = this.$el.style.maxHeight; } - - if (this.cachedScrollHeight !== this.$el.scrollHeight) { - this.$el.style.height = '' - this.$el.style.height = this.$el.scrollHeight + 'px'; - - if (parseFloat(this.$el.style.height) >= parseFloat(this.$el.style.maxHeight)) { - this.$el.style.overflowY = "scroll"; - this.$el.style.height = this.$el.style.maxHeight; - } - else { - this.$el.style.overflow = "hidden"; - } - - this.cachedScrollHeight = this.$el.scrollHeight; + else { + this.$el.style.overflow = "hidden"; } }, onInput(event) {