Field
Composable label, description, and error chrome. The default export is a preset (label, description, errorMessage, htmlFor). Compose Field.Root, Field.Label, Field.Control, Field.Description, and Field.Error when you need native constraint messages or custom controls.
Do not pass label on TextField inside Field.Root — use Field parts around a control without FieldMeta, or use TextField’s label / description / errorMessage without Field parts.
Examples
Default
Any input composes the shared field chrome.
import { Field } from '@var-ui/react';
<Field
label="Custom control"
description="Any input composes the shared field chrome."
htmlFor="custom-range"
>
<input id="custom-range" type="range" />
</Field>Parts
import { Button, Field } from '@var-ui/react';
<form
onSubmit={(event) => {
event.preventDefault();
}}
>
<Field.Root name="amount">
<Field.Label>Amount</Field.Label>
<Field.Control>
<input name="amount" required />
</Field.Control>
<Field.Description>In USD</Field.Description>
<Field.Error />
</Field.Root>
<Button type="submit">Save</Button>
</form>Validity attributes
Field.Root sets these attributes for CSS:
| Attribute | When |
|---|---|
data-invalid | The field is invalid (controlled invalid, native constraint, error content, or a form error). |
data-valid | Touched or dirty, and not invalid. |
data-dirty | The value differs from the default. |
data-touched | The control has been blurred at least once. |
data-filled | The control has a non-empty value (checkbox/radio: checked). |
data-disabled | The control is disabled. |
invalid is controlled when passed. If omitted, it is derived from native validity, Field.Error content, or a matching Form errors entry. Field.Error forceMount only keeps the error slot in the layout; it does not mark the field invalid.
Props
Accessibility
Built on React Aria Components where applicable.