From 15567aeae664249e23ecd1d56e8e0d92debaaaaa Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:26:26 +0100 Subject: [PATCH] fix(web): update description height when navigating between assets --- web/src/lib/actions/autogrow.ts | 24 ++++++++++++++----- .../asset-viewer/activity-viewer.svelte | 9 +------ .../autogrow-textarea.svelte | 11 +++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/web/src/lib/actions/autogrow.ts b/web/src/lib/actions/autogrow.ts index 664039cb2a6bd..0e6dec8e8180c 100644 --- a/web/src/lib/actions/autogrow.ts +++ b/web/src/lib/actions/autogrow.ts @@ -1,7 +1,19 @@ -export const autoGrowHeight = (textarea?: HTMLTextAreaElement, height = 'auto') => { - if (!textarea) { - return; - } - textarea.style.height = height; - textarea.style.height = `${textarea.scrollHeight}px`; +import { tick } from 'svelte'; +import type { Action } from 'svelte/action'; + +type Parameters = { + height?: string; + value: string; // added to enable reactivity +}; + +export const autoGrowHeight: Action = (textarea, { height = 'auto' }) => { + const update = () => { + void tick().then(() => { + textarea.style.height = height; + textarea.style.height = `${textarea.scrollHeight}px`; + }); + }; + + update(); + return { update }; }; diff --git a/web/src/lib/components/asset-viewer/activity-viewer.svelte b/web/src/lib/components/asset-viewer/activity-viewer.svelte index 34940aee56c9d..ce0ca9ac566e2 100644 --- a/web/src/lib/components/asset-viewer/activity-viewer.svelte +++ b/web/src/lib/components/asset-viewer/activity-viewer.svelte @@ -77,7 +77,6 @@ onClose, }: Props = $props(); - let textArea: HTMLTextAreaElement | undefined = $state(); let innerHeight: number = $state(0); let activityHeight: number = $state(0); let chatHeight: number = $state(0); @@ -142,10 +141,6 @@ }); reactions.push(data); - if (textArea) { - textArea.style.height = '18px'; - } - message = ''; onAddComment(); // Re-render the activity feed @@ -306,11 +301,9 @@