Skip to content

Field

import { Field } from 'yarcl';

Field renders the label, helper text and error, and wires them to its control: the control gets an id, aria-describedby, aria-invalid and required automatically.

As it appears on your ID.

Enter a valid email address.

<Field label="Full name" description="As it appears on your ID." required>
<Input placeholder="Ada Lovelace" />
</Field>
<Field label="Email" error={errors.email}>
<Input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
</Field>

Works with Input, Textarea, Select, Combobox, Checkbox and Switch. For radios, use RadioGroup.

  • The label uses defaults.labelStyle; helper and error text use defaults.helperStyle.
  • Errors, the invalid border and the required marker use defaults.errorColor.
  • The label is a real <label> connected with htmlFor.
  • Helper text and the error are announced as the control’s description.
  • Don’t set the control’s id yourself; Field manages it.
PropTypeDefaultDescription
children requiredReactNodeA single form control: Input, Textarea, Checkbox or Switch.
label requiredReactNodeVisible label for the control.
descriptionReactNodeHelper text shown below the control.
errorReactNodeError message. When set, the control is marked invalid and styled with defaults.errorColor.
requiredbooleanMarks the control as required and shows an indicator next to the label.