Components
Field
Wraps one form control with a linked label, a description and a validation error.
import { Field, Input } from "@openperf/deft";
<Field.Root>
<Field.Label>Email</Field.Label>
<Input.Root name="email" type="email" />
<Field.Description>We send the invitation to this address.</Field.Description>
</Field.Root>;When to use
| Need | Component |
|---|---|
| Control with a visible label, stacked in a form | Field |
| Label and control side by side in a settings row | List.Field in List |
| Control without a visible label, such as a search | The control alone, with aria-label |
Anatomy
<Field.Root>
<Field.Label />
<Input.Root /> {/* or Textarea, Select, OTP input */}
<Field.Description />
<Field.Error />
</Field.Root>Field.Label is linked to an Input, Textarea or OTP input without htmlFor and id. For a Select, set htmlFor on the label and id on Select.Trigger.
Prop on Field.Root | Effect |
|---|---|
invalid | Marks the control invalid: Input, Textarea and OTP input show a danger ring |
disabled | Disables the control and dims the label |
Validation
Field.Error appears when the control fails validation; match narrows it to one key of the native ValidityState, such as valueMissing. match={true} always shows it, so for a server error render it only when there is a message:
<Field.Root invalid={Boolean(error)}>
<Field.Label>Email</Field.Label>
<Input.Root name="email" type="email" />
{error && <Field.Error match={true}>{error}</Field.Error>}
</Field.Root>Inline label
Put a Switch or Checkbox inside Field.Label, before the text: a click on the text toggles the control.
API
No part declares props of its own. The Base UI props used most are invalid, disabled and name on Field.Root, and match on Field.Error. Field.Control, Field.Validity and Field.Item are Base UI parts exported without Deft styles.