Skip to content

Input

A native 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. An error state sets aria-invalid and the error border. See Field for pairing it with a Hint or a Field.StateIcon.

<Field class="flex flex-col gap-1">
<Label>Email</Label>
<Input type="email" class="w-64" bind:value />
</Field>

To add an icon or a suffix, put the input in an Input.Group.

<Field state="error">
<Input.Group>
<Input type="email" bind:value />
<Field.StateIcon />
</Input.Group>
</Field>
<Input
  placeholder="you@viam.com"
  state="none"
  disabled={false}
  readonly={false}
/>
  • A real <input>, so every native attribute and event handler passes straight through.
  • bind:value plus oninput, onchange, onblur, and the rest, side by side.
  • Three contextual states, info, warn, and error, each with a matching Field.StateIcon. none shows no icon.
  • Input.Group frames the input with icons, units, and buttons.
  • Reads controlId, disabled, required, state, and aria-describedby from an enclosing Field.

Input is one bare <input> and needs no parts. Input.Group is a part for adornments. Inside it the input goes borderless and the group wears the frame. Children go in any order.

<Input />
<Input.Group>
<Icon />
<Input />
<span>unit</span>
<Field.StateIcon />
<button>trailing action</button>
</Input.Group>

bind:value on the input. Inside a Field the label and hint wire themselves to it.

Lowercase letters, numbers, and dashes.

value: rover-1

Code
TwoWay.svelte
<script lang="ts">
import { Field, Hint, Input, Label } from "@viamrobotics/prime-ui";
let name = $state("rover-1");
</script>
<div class="not-content">
<Field class="flex max-w-xs flex-col gap-1">
<Label>Machine name</Label>
<Input bind:value={name} placeholder="rover-1" />
<Hint>Lowercase letters, numbers, and dashes.</Hint>
</Field>
<p class="mt-3 text-sm text-subtle-2">value: <code>{name}</code></p>
</div>

The input is native, so onblur and the other handlers work alongside the binding. Set state on the field and the input, the hint, and the Field.StateIcon all follow it.

Lowercase letters, numbers, and dashes. Validated on blur.

Code
Validated.svelte
<script lang="ts">
import { Field, Hint, Input, Label } from "@viamrobotics/prime-ui";
let name = $state("Rover 1");
let touched = $state(false);
const isValid = $derived(/^[a-z0-9-]+$/.test(name));
const fieldState = $derived(touched && !isValid ? "error" : "none");
</script>
<Field class="not-content flex max-w-xs flex-col gap-1" state={fieldState}>
<Label>Machine name</Label>
<Input.Group>
<Input bind:value={name} onblur={() => (touched = true)} />
<Field.StateIcon />
</Input.Group>
<Hint>Lowercase letters, numbers, and dashes. Validated on blur.</Hint>
</Field>

For the controlled mode, where your setter can decline a keystroke, see State & binding.

A leading Icon, the input, and a unit suffix inside an Input.Group. You set the width, here with class="w-64" on the group. Pressing the group’s padding or the icon focuses the input.

ms
Code
Adorned.svelte
<script lang="ts">
import { mdiMagnify } from "@mdi/js";
import { Icon, Input } from "@viamrobotics/prime-ui";
let query = $state("");
</script>
<div class="not-content">
<Input.Group class="w-64">
<Icon icon={mdiMagnify} />
<Input bind:value={query} placeholder="Search parts" aria-label="Search parts" />
<span class="text-sm text-subtle-2">ms</span>
</Input.Group>
</div>

Put a Field.StateIcon after the input inside an Input.Group to show the icon within the border. Standalone it takes its own state, and inside a Field it follows the field.

Validation states, with Field.StateIcon

Disabled and read-only

class lands on the <input>. The input has no wrapper and no layout utilities, including 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, which Select.Trigger wears too. It reads the attributes below, so Input.Group takes its border, its disabled and read-only backgrounds, and its state colors from the input directly inside it with no JavaScript. The group takes class on its <div> and has no layout utilities either, so give it a width.

Hook Where
data-field-state On the input for info, warn, and error
aria-invalid On the input in the error state

Field.StateIcon takes class on its <svg>, merged with the state color.

Native text input behavior. Nothing is added or intercepted.

PropTypeDefaultDescription
bind:valuestringThe text in the input.
type| 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'date' | 'datetime-local' | 'month' | 'time' | 'week' | 'color' | 'hidden''text'A native type whose value is a string. Listed out, because Svelte's HTMLInputTypeAttribute admits any string. number and range bind a number, so they belong to [NumberInput](./NumberInput.svelte). checkbox, radio, and file bind something other than value.
stateFieldStateContextual state. Defaults to the enclosing field's state.

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

Input.Group

Wraps an input with leading or trailing content, such as an icon, a unit suffix, or a state icon. The group wears the input class from @viamrobotics/tailwind-config, and the Input or NumberInput directly inside it hands over its border, padding, and focus ring. Clicking the group’s padding or any non-interactive content focuses the input.

A disabled or readonly input restyles the group, and the input’s error or warn state colors the group’s border. The frame reads the input’s attributes in CSS, so no JavaScript runs. Only an <input> counts, so a disabled button beside it leaves the group alone.

<Input.Group>
<Icon icon={mdiMagnify} class="text-subtle-2" />
<Input placeholder="Search" bind:value />
<Field.StateIcon state="error" />
</Input.Group>

Takes extraClasses, children, onpointerdown, ...restProps }: Props as its props.