refac: textarea

This commit is contained in:
Timothy Jaeryang Baek
2024-11-26 14:14:26 -08:00
parent 4383306770
commit 789e1db260
2 changed files with 275 additions and 281 deletions

View File

@@ -13,28 +13,15 @@
// Adjust height on mount and after setting the element.
onMount(async () => {
await tick();
adjustHeight();
});
// This reactive statement runs whenever `value` changes
$: adjustHeight();
// Adjust height to match content
const adjustHeight = () => {
if (textareaElement) {
// Reset height to calculate the correct scroll height
textareaElement.style.height = 'auto';
textareaElement.style.height = `${textareaElement.scrollHeight}px`;
}
};
</script>
<textarea
bind:this={textareaElement}
bind:value
{placeholder}
on:input={adjustHeight}
class={className}
style="field-sizing: content;"
{rows}
{required}
/>