mirror of
https://github.com/immich-app/immich.git
synced 2025-12-15 06:24:23 +03:00
fix: autogrow textarea bugs during animation
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { tick } from 'svelte';
|
|
||||||
import type { Action } from 'svelte/action';
|
import type { Action } from 'svelte/action';
|
||||||
|
|
||||||
type Parameters = {
|
type Parameters = {
|
||||||
@@ -6,14 +5,19 @@ type Parameters = {
|
|||||||
value: string; // added to enable reactivity
|
value: string; // added to enable reactivity
|
||||||
};
|
};
|
||||||
|
|
||||||
export const autoGrowHeight: Action<HTMLTextAreaElement, Parameters> = (textarea, { height = 'auto' }) => {
|
export const autoGrowHeight: Action<HTMLTextAreaElement, Parameters> = (textarea) => {
|
||||||
const update = () => {
|
const resize = () => {
|
||||||
void tick().then(() => {
|
textarea.style.minHeight = '0';
|
||||||
textarea.style.height = height;
|
textarea.style.height = 'auto';
|
||||||
textarea.style.height = `${textarea.scrollHeight}px`;
|
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
update();
|
resize();
|
||||||
return { update };
|
textarea.addEventListener('input', resize);
|
||||||
|
return {
|
||||||
|
update: resize,
|
||||||
|
destroy() {
|
||||||
|
textarea.removeEventListener('input', resize);
|
||||||
|
},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -248,7 +248,8 @@
|
|||||||
<textarea
|
<textarea
|
||||||
{disabled}
|
{disabled}
|
||||||
bind:value={message}
|
bind:value={message}
|
||||||
use:autoGrowHeight={{ height: '5px', value: message }}
|
rows="1"
|
||||||
|
use:autoGrowHeight={{ value: message }}
|
||||||
placeholder={disabled ? $t('comments_are_disabled') : $t('say_something')}
|
placeholder={disabled ? $t('comments_are_disabled') : $t('say_something')}
|
||||||
use:shortcut={{
|
use:shortcut={{
|
||||||
shortcut: { key: 'Enter' },
|
shortcut: { key: 'Enter' },
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
class="resize-none {className}"
|
class="resize-none {className}"
|
||||||
onfocusout={updateContent}
|
onfocusout={updateContent}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
|
rows="1"
|
||||||
use:shortcut={{
|
use:shortcut={{
|
||||||
shortcut: { key: 'Enter', ctrl: true },
|
shortcut: { key: 'Enter', ctrl: true },
|
||||||
onShortcut: (e) => e.currentTarget.blur(),
|
onShortcut: (e) => e.currentTarget.blur(),
|
||||||
|
|||||||
Reference in New Issue
Block a user