Fixed #733 - Textarea does not auto resize its height when created

pull/800/head
Cagatay Civici 2020-12-09 17:03:33 +03:00
parent c30e0cdb23
commit 1c5fac7abe
1 changed files with 8 additions and 18 deletions

View File

@ -9,7 +9,6 @@ export default {
modelValue: null, modelValue: null,
autoResize: Boolean autoResize: Boolean
}, },
cachedScrollHeight: null,
mounted() { mounted() {
if (this.$el.offsetParent && this.autoResize) { if (this.$el.offsetParent && this.autoResize) {
this.resize(); this.resize();
@ -22,24 +21,15 @@ export default {
}, },
methods: { methods: {
resize() { resize() {
if (!this.cachedScrollHeight) { this.$el.style.height = 'auto';
this.cachedScrollHeight = this.$el.scrollHeight; this.$el.style.height = this.$el.scrollHeight + 'px';
this.$el.style.overflow = "hidden";
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 {
if (this.cachedScrollHeight !== this.$el.scrollHeight) { this.$el.style.overflow = "hidden";
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;
} }
}, },
onInput(event) { onInput(event) {