mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
40 lines
1,010 B
Svelte
40 lines
1,010 B
Svelte
|
|
<script lang="ts">
|
||
|
|
import { autoGrowHeight } from '$lib/actions/autogrow';
|
||
|
|
import { shortcut } from '$lib/actions/shortcut';
|
||
|
|
import { tick } from 'svelte';
|
||
|
|
|
||
|
|
export let content: string = '';
|
||
|
|
let className: string = '';
|
||
|
|
export { className as class };
|
||
|
|
export let onContentUpdate: (newContent: string) => void = () => null;
|
||
|
|
export let placeholder: string = '';
|
||
|
|
|
||
|
|
let textarea: HTMLTextAreaElement;
|
||
|
|
$: newContent = content;
|
||
|
|
|
||
|
|
$: if (textarea) {
|
||
|
|
newContent;
|
||
|
|
void tick().then(() => autoGrowHeight(textarea));
|
||
|
|
}
|
||
|
|
|
||
|
|
const updateContent = () => {
|
||
|
|
if (content === newContent) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
onContentUpdate(newContent);
|
||
|
|
};
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<textarea
|
||
|
|
bind:this={textarea}
|
||
|
|
class="resize-none {className}"
|
||
|
|
on:focusout={updateContent}
|
||
|
|
on:input={(e) => (newContent = e.currentTarget.value)}
|
||
|
|
{placeholder}
|
||
|
|
use:shortcut={{
|
||
|
|
shortcut: { key: 'Enter', ctrl: true },
|
||
|
|
onShortcut: (e) => e.currentTarget.blur(),
|
||
|
|
}}
|
||
|
|
data-testid="autogrow-textarea">{content}</textarea
|
||
|
|
>
|