2024-10-20 06:17:47 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { onMount, tick } from 'svelte';
|
|
|
|
|
|
|
|
|
|
export let value = '';
|
|
|
|
|
export let placeholder = '';
|
|
|
|
|
|
2024-10-21 02:04:30 +00:00
|
|
|
export let rows = 1;
|
|
|
|
|
export let required = false;
|
|
|
|
|
|
2024-10-20 06:17:47 +00:00
|
|
|
export let className =
|
|
|
|
|
'w-full rounded-lg px-3 py-2 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none resize-none h-full';
|
|
|
|
|
|
|
|
|
|
let textareaElement;
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
await tick();
|
|
|
|
|
if (textareaElement) {
|
2024-10-24 10:10:17 +00:00
|
|
|
await tick();
|
2024-10-21 02:04:30 +00:00
|
|
|
setTimeout(adjustHeight, 0);
|
2024-10-20 06:17:47 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const adjustHeight = () => {
|
|
|
|
|
if (textareaElement) {
|
|
|
|
|
textareaElement.style.height = '';
|
|
|
|
|
textareaElement.style.height = `${textareaElement.scrollHeight}px`;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<textarea
|
|
|
|
|
bind:this={textareaElement}
|
|
|
|
|
bind:value
|
|
|
|
|
{placeholder}
|
2024-10-21 02:04:30 +00:00
|
|
|
on:input={adjustHeight}
|
2024-10-24 10:10:17 +00:00
|
|
|
on:focus={adjustHeight}
|
2024-10-20 06:17:47 +00:00
|
|
|
class={className}
|
2024-10-21 02:04:30 +00:00
|
|
|
{rows}
|
|
|
|
|
{required}
|
2024-10-20 06:17:47 +00:00
|
|
|
/>
|