Skip to content

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 shows rows lines elsewhere.
  • Three contextual states, info, warn, and error, styled like Input.
  • Reads controlId, disabled, required, state, and aria-describedby from an enclosing Field.

bind:value on the textarea, with the native handlers alongside it. State & binding covers both modes.

length: 0

Code
TwoWay.svelte
<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>

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
InField.svelte
<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>

Set state on the field and the textarea, the hint, and aria-invalid all follow it.

Validated on blur.

Code
Validated.svelte
<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>

Something is wrong.

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

Native textarea behavior. Nothing is added or intercepted.

PropTypeDefaultDescription
bind:valuestringThe text in the textarea.
rowsnumber3Visible lines where the browser cannot size the box to its content.
stateFieldStateContextual state. Defaults to the enclosing field's state.

Plus everything in Omit<HTMLTextareaAttributes, 'value' | 'children'>, spread onto the element.