Textarea
A native multi-line text input with the Viam border and padding. Inside a
Field it takes its id (the field’s controlId), disabled,
required, state, and aria-describedby from there. It grows with its content where the
browser supports field-sizing: content, and shows rows lines elsewhere.
<Field class="flex flex-col gap-1"> <Label>Notes</Label> <Textarea class="w-64" bind:value /></Field><Textarea
rows={3}
placeholder="Describe the machine"
disabled={false}
readonly={false}
/>- A real
<textarea>, so every native attribute and event handler passes straight through. - Grows with its content where the browser supports
field-sizing: content, and showsrowslines elsewhere. - Three contextual states,
info,warn, anderror, styled likeInput. - Reads
controlId,disabled,required,state, andaria-describedbyfrom an enclosingField.
Two-way binding
Section titled “Two-way binding”bind:value on the textarea, with the native handlers alongside it. State & binding covers both modes.
length: 0
Code
<script lang="ts"> import { Textarea } from "@viamrobotics/prime-ui";
let notes = $state("");</script>
<div class="not-content"> <Textarea class="w-64" bind:value={notes} aria-label="Notes" placeholder="Notes" />
<p class="mt-3 text-sm text-subtle-2">length: <code>{notes.length}</code></p></div>In a field
Section titled “In a field”Inside a Field the label and hint wire themselves to the textarea. rows sets the height where the box cannot grow to its content.
Shown on the machine's overview page.
Code
<script lang="ts"> import { Field, Hint, Label, Textarea } from "@viamrobotics/prime-ui";
let description = $state("");</script>
<Field class="not-content flex max-w-xs flex-col gap-1"> <Label>Description</Label> <Textarea bind:value={description} rows={4} /> <Hint>Shown on the machine's overview page.</Hint></Field>Validation on blur
Section titled “Validation on blur”Set state on the field and the textarea, the hint, and aria-invalid all follow it.
Validated on blur.
Code
<script lang="ts"> import { Field, Hint, Label, Textarea } from "@viamrobotics/prime-ui";
let reason = $state(""); let touched = $state(false);
const fieldState = $derived(touched && reason.trim() === "" ? "error" : "none");</script>
<Field class="not-content flex max-w-xs flex-col gap-1" state={fieldState} required> <Label>Reason</Label> <Textarea bind:value={reason} onblur={() => (touched = true)} /> <Hint>{fieldState === "error" ? "A reason is required." : "Validated on blur."}</Hint></Field>States
Section titled “States”Something is wrong.
Styling
Section titled “Styling”class lands on the <textarea>. It has no wrapper and no width, so set one yourself or let a flex or grid parent stretch it.
The border, padding, and state colors are the input component class from @viamrobotics/tailwind-config, the same one Input wears. Height comes from field-sizing: content, with rows as the fallback in browsers without it.
| Hook | Where |
|---|---|
data-field-state |
On the textarea for info, warn, and error |
aria-invalid |
On the textarea in the error state |
Keyboard
Section titled “Keyboard”Native textarea behavior. Nothing is added or intercepted.
| Prop | Type | Default | Description |
|---|---|---|---|
bind:value | string | The text in the textarea. | |
rows | number | 3 | Visible lines where the browser cannot size the box to its content. |
state | FieldState | Contextual state. Defaults to the enclosing field's state. |
Plus everything in Omit<HTMLTextareaAttributes, 'value' | 'children'>, spread onto the element.