Field
Data inputA form field: Field holds a Field.Label, one control (Input …) and an optional Field.Description and Field.Error. It wires them for you: the label points at the control, the description and a shown error describe it, and a shown error (or invalid) marks it aria-invalid. disabled disables the control. Field.Set with a Field.Legend groups related fields; Field.Group stacks fields; orientation puts the label beside the control.
import { Field } from '@limerdev/zest'; id, for, aria-describedby or aria-invalid by hand inside a Field: it does that. More than one control in a Field: use one Field per control, in a Field.Group. Error text in a Field.Description: use Field.Error.Examples
Label description and error
The Field wires its label, description and error to the control: leave the field to see the error appear and the input turn invalid.
Shown in the sidebar and in emails.
<script lang="ts">
import { Field, Input, type FieldErrorItem } from '@limerdev/zest';
let name = $state('');
let touched = $state(false);
const errors: FieldErrorItem[] = $derived(
touched && name.trim() === '' ? [{ message: 'Enter a name.' }] : []
);
</script>
<Field.Root class="max-w-sm">
<Field.Label>Project name</Field.Label>
<Input bind:value={name} onblur={() => (touched = true)} placeholder="Zest" />
<Field.Description>Shown in the sidebar and in emails.</Field.Description>
<Field.Error {errors} />
</Field.Root> Several errors and disabled
Several errors show as a list. disabled on the Field disables its control.
- Use at least 12 characters.
- Use a number or a symbol.
Set when the customer is created.
<script lang="ts">
import { Field, Input, type FieldErrorItem } from '@limerdev/zest';
const errors: FieldErrorItem[] = [
{ message: 'Use at least 12 characters.' },
{ message: 'Use a number or a symbol.' }
];
</script>
<div class="grid w-full max-w-sm gap-6">
<Field.Root>
<Field.Label>Password</Field.Label>
<Input type="password" value="short" />
<Field.Error {errors} />
</Field.Root>
<Field.Root disabled>
<Field.Label>Customer number</Field.Label>
<Input value="C-1042" />
<Field.Description>Set when the customer is created.</Field.Description>
</Field.Root>
</div> A form
Field.Set and Field.Legend group related fields. responsive puts labels in a column beside their controls when there is room; horizontal puts a label beside its control.
<script lang="ts">
import { Button, Field, Input } from '@limerdev/zest';
</script>
<form class="flex w-full max-w-xl flex-col gap-6" onsubmit={(event) => event.preventDefault()}>
<Field.Set>
<Field.Legend>Billing</Field.Legend>
<Field.Description>Where invoices are sent.</Field.Description>
<Field.Group>
<Field.Root orientation="responsive">
<Field.Label>Company</Field.Label>
<Input />
</Field.Root>
<Field.Root orientation="responsive">
<Field.Label>Invoice email</Field.Label>
<Input type="email" />
</Field.Root>
<Field.Root orientation="horizontal">
<Field.Content>
<Field.Label>VAT number</Field.Label>
<Field.Description>Leave empty outside the EU.</Field.Description>
</Field.Content>
<Input class="max-w-48" />
</Field.Root>
</Field.Group>
</Field.Set>
<Button type="submit" class="self-start">Save</Button>
</form> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Field.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Disable the control and dim the field. |
| invalid | boolean | false | Mark the control invalid without an error message (a shown Field.Error does it too). |
| orientation | "horizontal" | "vertical" | "responsive" | 'vertical' | Where the label goes: above the control (vertical), beside it (horizontal), or beside it when the field group is wide enough (responsive). |
Field.Set
No props of its own beyond the common ones.
Field.Legend
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "legend" | "label" | 'legend' | legend for a section heading, label for a legend that names a group of choices like a label. |
Field.Group
No props of its own beyond the common ones.
Field.Content
No props of its own beyond the common ones.
Field.Label
No props of its own beyond the common ones.
Field.Title
No props of its own beyond the common ones.
Field.Description
No props of its own beyond the common ones.
Field.Error
| Prop | Type | Default | Description |
|---|---|---|---|
| errors | FieldErrorItem[] | – | Validation errors, as form libraries return them; their messages are listed. |