Svelte action to automatically adjust textarea height to match its contents.
Simply wraps autosize by Jack Moore in a Svelte action.
See the autosize website for additional documentation.
npm install svelte-autosize
<script>
import autosize from 'svelte-autosize';
</script>
<textarea use:autosize></textarea>
If you need to reset the textarea height, you can use autosize.update(textarea)
. For example:
<script>
import {tick} from 'svelte';
import autosize from 'svelte-autosize';
let textarea;
let value = '';
async function reset() {
value = '';
await tick();
autosize.update(textarea);
}
</script>
<textarea use:autosize bind:this={textarea} bind:value></textarea>
<button on:click={reset}>Reset</button>