Compare commits

...

1 Commits

Author SHA1 Message Date
midzelis
2a3c1c6e15 fix: autogrow textarea bugs during animation 2025-12-09 15:50:23 +00:00
3 changed files with 16 additions and 10 deletions

View File

@@ -1,4 +1,3 @@
import { tick } from 'svelte';
import type { Action } from 'svelte/action';
type Parameters = {
@@ -6,14 +5,19 @@ type Parameters = {
value: string; // added to enable reactivity
};
export const autoGrowHeight: Action<HTMLTextAreaElement, Parameters> = (textarea, { height = 'auto' }) => {
const update = () => {
void tick().then(() => {
textarea.style.height = height;
textarea.style.height = `${textarea.scrollHeight}px`;
});
export const autoGrowHeight: Action<HTMLTextAreaElement, Parameters> = (textarea) => {
const resize = () => {
textarea.style.minHeight = '0';
textarea.style.height = 'auto';
textarea.style.height = `${textarea.scrollHeight}px`;
};
update();
return { update };
resize();
textarea.addEventListener('input', resize);
return {
update: resize,
destroy() {
textarea.removeEventListener('input', resize);
},
};
};

View File

@@ -248,7 +248,8 @@
<textarea
{disabled}
bind:value={message}
use:autoGrowHeight={{ height: '5px', value: message }}
rows="1"
use:autoGrowHeight={{ value: message }}
placeholder={disabled ? $t('comments_are_disabled') : $t('say_something')}
use:shortcut={{
shortcut: { key: 'Enter' },

View File

@@ -26,6 +26,7 @@
class="resize-none {className}"
onfocusout={updateContent}
{placeholder}
rows="1"
use:shortcut={{
shortcut: { key: 'Enter', ctrl: true },
onShortcut: (e) => e.currentTarget.blur(),