mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(web): set album description textarea height correctly (#9880)
* fix(web): set description textarea content correctly * Deduplicate description textarea * Add strict types to function * Add strict types to functions * Add default parameter values * Add tests covering AutogrowTextarea * Add another test and lint the files * Add a test, fix a typo * Implement suggestions * Remove use of $$restProp
This commit is contained in:
parent
7524c746a6
commit
21718cc343
5 changed files with 130 additions and 47 deletions
|
|
@ -0,0 +1,39 @@
|
|||
<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
|
||||
>
|
||||
Loading…
Add table
Add a link
Reference in a new issue