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.

Please enter a valid email address.

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

PropTypeDefaultDescription
labelReactNode—Field label text
descriptionReactNode—Helper text below the control
errorReactNode—Error message — sets control to invalid when present
requiredbooleanfalseShow required indicator on label. Also shown when the control has required
childrenReactNode—The form control (Input, Textarea, Select, etc.)
sxStyleXStyles—StyleX style override for the root
labelSxStyleXStyles—StyleX style override for the label
descriptionSxStyleXStyles—StyleX style override for the description
errorSxStyleXStyles—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-labelledby and aria-describedby.
  • Error state sets aria-invalid="true" on the child control.
  • required on the control announces the field as required and adds the asterisk. required on Field only adds the asterisk.
  • Inside Form, a submit validates the control. If the control is invalid and Field has no error, Field shows the browser's validation message.