Compare commits

...
Author SHA1 Message Date
iamsivin 201747d6a2 fix: Resizable textarea height issue 2023-11-15 11:42:05 +05:30
3 changed files with 15 additions and 6 deletions
@@ -4,6 +4,7 @@
v-model="articleTitle" v-model="articleTitle"
type="text" type="text"
rows="1" rows="1"
:min-height="6"
class="article-heading" class="article-heading"
:placeholder="$t('HELP_CENTER.EDIT_ARTICLE.TITLE_PLACEHOLDER')" :placeholder="$t('HELP_CENTER.EDIT_ARTICLE.TITLE_PLACEHOLDER')"
@focus="onFocus" @focus="onFocus"
@@ -19,6 +19,7 @@
v-model="greetingsMessage" v-model="greetingsMessage"
rows="4" rows="4"
type="text" type="text"
:min-height="6"
class="greetings--textarea" class="greetings--textarea"
:label="label" :label="label"
:placeholder="placeholder" :placeholder="placeholder"
@@ -1,6 +1,7 @@
<template> <template>
<textarea <textarea
ref="textarea" ref="textarea"
:style="{ height: textareaHeight }"
:placeholder="placeholder" :placeholder="placeholder"
:value="value" :value="value"
@input="onInput" @input="onInput"
@@ -18,6 +19,7 @@ import {
} from 'dashboard/helper/editorHelper'; } from 'dashboard/helper/editorHelper';
const TYPING_INDICATOR_IDLE_TIME = 4000; const TYPING_INDICATOR_IDLE_TIME = 4000;
const PIXELS_PER_REM = 16;
export default { export default {
props: { props: {
placeholder: { placeholder: {
@@ -50,6 +52,7 @@ export default {
data() { data() {
return { return {
idleTimer: null, idleTimer: null,
textareaHeight: `${this.minHeight * PIXELS_PER_REM}px`,
}; };
}, },
computed: { computed: {
@@ -91,12 +94,16 @@ export default {
}, },
methods: { methods: {
resizeTextarea() { resizeTextarea() {
this.$el.style.height = 'auto'; const textarea = this.$refs.textarea;
if (!this.value) { if (!textarea || !this.value) return;
this.$el.style.height = `${this.minHeight}rem`; // Reset the height to the minimum first to allow shrinking
} else { const minHeightPx = this.minHeight * PIXELS_PER_REM;
this.$el.style.height = `${this.$el.scrollHeight}px`; this.textareaHeight = `${minHeightPx}px`;
}
this.$nextTick(() => {
const newHeight = Math.max(textarea.scrollHeight, minHeightPx);
this.textareaHeight = `${newHeight}px`; // Update the height
});
}, },
// The toggleSignatureInEditor gets the new value from the // The toggleSignatureInEditor gets the new value from the
// watcher, this means that if the value is true, the signature // watcher, this means that if the value is true, the signature