1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-21 18:16:55 +02:00

fix(web): update description height when navigating between assets (#14145)

This commit is contained in:
Michel Heusschen 2024-11-14 16:59:30 +01:00 committed by GitHub
parent d1085e8a02
commit 1fa0122eda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 22 deletions

View File

@ -1,7 +1,19 @@
export const autoGrowHeight = (textarea?: HTMLTextAreaElement, height = 'auto') => { import { tick } from 'svelte';
if (!textarea) { import type { Action } from 'svelte/action';
return;
} type Parameters = {
textarea.style.height = height; height?: string;
textarea.style.height = `${textarea.scrollHeight}px`; 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`;
});
};
update();
return { update };
}; };

View File

@ -77,7 +77,6 @@
onClose, onClose,
}: Props = $props(); }: Props = $props();
let textArea: HTMLTextAreaElement | undefined = $state();
let innerHeight: number = $state(0); let innerHeight: number = $state(0);
let activityHeight: number = $state(0); let activityHeight: number = $state(0);
let chatHeight: number = $state(0); let chatHeight: number = $state(0);
@ -142,10 +141,6 @@
}); });
reactions.push(data); reactions.push(data);
if (textArea) {
textArea.style.height = '18px';
}
message = ''; message = '';
onAddComment(); onAddComment();
// Re-render the activity feed // Re-render the activity feed
@ -306,11 +301,9 @@
<div class="flex w-full items-center gap-4"> <div class="flex w-full items-center gap-4">
<textarea <textarea
{disabled} {disabled}
bind:this={textArea}
bind:value={message} bind:value={message}
use:autoGrowHeight={'5px'} use:autoGrowHeight={{ height: '5px', value: message }}
placeholder={disabled ? $t('comments_are_disabled') : $t('say_something')} placeholder={disabled ? $t('comments_are_disabled') : $t('say_something')}
oninput={() => autoGrowHeight(textArea, '5px')}
use:shortcut={{ use:shortcut={{
shortcut: { key: 'Enter' }, shortcut: { key: 'Enter' },
onShortcut: () => handleSendComment(), onShortcut: () => handleSendComment(),

View File

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { autoGrowHeight } from '$lib/actions/autogrow'; import { autoGrowHeight } from '$lib/actions/autogrow';
import { shortcut } from '$lib/actions/shortcut'; import { shortcut } from '$lib/actions/shortcut';
import { tick } from 'svelte';
interface Props { interface Props {
content?: string; content?: string;
@ -12,13 +11,9 @@
let { content = '', class: className = '', onContentUpdate = () => null, placeholder = '' }: Props = $props(); let { content = '', class: className = '', onContentUpdate = () => null, placeholder = '' }: Props = $props();
let textarea: HTMLTextAreaElement | undefined = $state();
let newContent = $state(content); let newContent = $state(content);
$effect(() => { $effect(() => {
if (textarea && newContent.length > 0) { newContent = content;
void tick().then(() => autoGrowHeight(textarea));
}
}); });
const updateContent = () => { const updateContent = () => {
@ -30,14 +25,14 @@
</script> </script>
<textarea <textarea
bind:this={textarea} bind:value={newContent}
class="resize-none {className}" class="resize-none {className}"
onfocusout={updateContent} onfocusout={updateContent}
oninput={(e) => (newContent = e.currentTarget.value)}
{placeholder} {placeholder}
use:shortcut={{ use:shortcut={{
shortcut: { key: 'Enter', ctrl: true }, shortcut: { key: 'Enter', ctrl: true },
onShortcut: (e) => e.currentTarget.blur(), onShortcut: (e) => e.currentTarget.blur(),
}} }}
use:autoGrowHeight={{ value: newContent }}
data-testid="autogrow-textarea">{content}</textarea data-testid="autogrow-textarea">{content}</textarea
> >