The textarea component is a multi-line text field for longer content such as comments and descriptions.
For validated forms, use FormTextarea inside a parent Form. FormTextarea requires Form context.
Setup
<script>
import { Textarea, Label } from '.';
</script> Default
<script>
import { Textarea, Label } from '.';
</script>
<Label for="textarea-id" class="mb-2">Your message</Label>
<Textarea id="textarea-id" placeholder="Your message" rows={4} name="message" class="w-full" /> Clearable
<script>
import { Textarea, Label } from '.';
</script>
<Label for="textarea-clearable" class="mb-2">Your message</Label>
<Textarea
clearable
id="textarea-clearable"
placeholder="Your message"
rows={4}
name="message"
class="w-full"
/> Header, footer, and addon
Use header, footer, and addon snippets for chrome around the field. Set wrapped for the bordered wrapper layout.
<script>
import { Textarea } from '.';
</script>
<Textarea wrapped rows={4} placeholder="Write something…">
{#snippet header()}
<div class="text-xs text-gray-500">Header</div>
{/snippet}
{#snippet footer()}
<div class="text-xs text-gray-500">Footer</div>
{/snippet}
</Textarea> Accessibility
- Associate with
Labelviafor/id. - Use
aria-describedbywithHelperfor hints and errors. clearableexposes a clear control; keep labels visible for screen readers.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Bindable value |
elementRef | HTMLTextAreaElement | — | Bindable textarea element |
header / footer / addon | Snippet | — | Chrome snippets |
wrapped | boolean | — | Use bordered wrapper layout |
divClass / innerClass | ClassValue | — | Layout classes |
headerClass / footerClass / addonClass | ClassValue | — | Snippet container classes |
textareaClass | ClassValue | — | Classes on <textarea> |
clearable | boolean | false | Show clear button |
clearableOnClick | () => void | — | Extra clear callback |
clearableClass / clearableSvgClass | ClassValue | — | Clear button styling |
clearableColor | CloseButton color | — | Clear icon color |
rows / cols / placeholder / disabled / required / name | native | — | HTML textarea attrs |
class | ClassValue | — | Extra classes |
FormTextarea
FormTextarea extends TextareaProps with required name, optional label and contextKey. Must be a child of Form.