fix: adjust height when value changes, close #429

This commit is contained in:
Xylight committed 2024-09-11 19:55:09 -07:00
1 parent f94a7e82eb
commit 3f93285392
2 files changed
+19 -9

No files matched your search

+11 -4
View File
@@ -1,13 +1,20 @@
<script lang="ts">
import { browser } from '$app/environment'
import { tick } from 'svelte'
export let label: string | undefined = undefined
export let value: string
export let required: boolean = false
let textarea: HTMLTextAreaElement
function adjustHeight() {
textarea.style.height = 'auto' // Reset height to auto to calculate new height
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
$: adjustHeight(value)
async function adjustHeight(value: string) {
await tick()
if (textarea) {
textarea.style.height = 'auto' // Reset height to auto to calculate new height
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
}
}
</script>
@@ -22,7 +29,7 @@
{/if}
<textarea
bind:this={textarea}
on:input={adjustHeight}
on:input={() => adjustHeight(value)}
bind:value
{required}
{...$$restProps}