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:valueplusoninput,onchange,onblur, and the rest, side by side.- Three contextual states,
info,warn, anderror, each with a matchingField.StateIcon.noneshows no icon. Input.Groupframes the input with icons, units, and buttons.- Reads
controlId,disabled,required,state, andaria-describedbyfrom an enclosingField.
Anatomy
Section titled “Anatomy”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>Two-way binding
Section titled “Two-way binding”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
<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>Validation on blur
Section titled “Validation on blur”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
<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.
With adornments
Section titled “With adornments”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.
Code
<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>States
Section titled “States”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
Styling
Section titled “Styling”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.
Keyboard
Section titled “Keyboard”Native text input behavior. Nothing is added or intercepted.
| Prop | Type | Default | Description |
|---|---|---|---|
bind:value | string | The 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. |
state | FieldState | Contextual 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.