Field
A wrapper that connects a label, description, and error message to a form control.
Import
import { Field } from '@matix/components/field';Usage
Wrap any form control in Field to get a connected label, optional description, and error message.
We'll never share your email.
With Description
<Field label="Password" description="Must be at least 8 characters.">
<Input type="password" />
</Field>Error State
Passing an error prop automatically sets the child control to its invalid state.
Required
If the control has required, the label shows a required indicator. Set required on Field to show the indicator without the control attribute.
<Field label="Full name">
<Input placeholder="Jane Doe" required />
</Field>With Different Controls
Field works with any matix form control.
<Field label="Message">
<Textarea placeholder="Your message…" />
</Field>
<Field label="Country">
<Select
options={[
{ value: 'us', label: 'United States' },
{ value: 'uk', label: 'United Kingdom' },
]}
/>
</Field>Groups of Controls
For a RadioGroup or a set of checkboxes, use Fieldset. The Field label is a <label> for one control, so a click on it selects the first option.
Custom Styles
import * as stylex from '@stylexjs/stylex';
const custom = stylex.create({
compact: { gap: '4px' },
});
<Field sx={custom.compact} label="Compact field">
<Input placeholder="Less spacing" />
</Field>;sx styles the root. To style one part, use labelSx, descriptionSx, or errorSx.
import * as stylex from '@stylexjs/stylex';
import { fontSize } from '@matix/tokens/typography.stylex';
const custom = stylex.create({
label: { fontSize: fontSize.base },
});
<Field label="Email" labelSx={custom.label}>
<Input type="email" />
</Field>;API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Field label text |
description | ReactNode | — | Helper text below the control |
error | ReactNode | — | Error message — sets control to invalid when present |
required | boolean | false | Show required indicator on label. Also shown when the control has required |
children | ReactNode | — | The form control (Input, Textarea, Select, etc.) |
sx | StyleXStyles | — | StyleX style override for the root |
labelSx | StyleXStyles | — | StyleX style override for the label |
descriptionSx | StyleXStyles | — | StyleX style override for the description |
errorSx | StyleXStyles | — | StyleX style override for the error message |
All other props are forwarded to the underlying Base UI Field.
Accessibility
- Wraps Base UI Field — automatically links label, description, and error to the control via
aria-labelledbyandaria-describedby. - Error state sets
aria-invalid="true"on the child control. requiredon the control announces the field as required and adds the asterisk.requiredonFieldonly adds the asterisk.- Inside
Form, a submit validates the control. If the control is invalid and Field has noerror, Field shows the browser's validation message.