Field

A component that provides labelling and validation for form controls.

Choose a unique username for your account.

Installation

pnpm dlx shadcn@latest add @lumi-ui/field

Anatomy

<Field>
  <FieldLabel />
  <FieldControl />
  <FieldDescription />
  <FieldItem />
  <FieldError />
  <FieldValidity />
</FieldRoot>

State and Validation

Required

Must be at least 8 characters long.

Error

Press enter to see the error.

Validity

{
  "state": {
    "badInput": false,
    "customError": false,
    "patternMismatch": false,
    "rangeOverflow": false,
    "rangeUnderflow": false,
    "stepMismatch": false,
    "tooLong": false,
    "tooShort": false,
    "typeMismatch": false,
    "valid": null,
    "valueMissing": false
  },
  "error": "",
  "errors": [],
  "value": null,
  "initialValue": null,
  "validity": {
    "badInput": false,
    "customError": false,
    "patternMismatch": false,
    "rangeOverflow": false,
    "rangeUnderflow": false,
    "stepMismatch": false,
    "tooLong": false,
    "tooShort": false,
    "typeMismatch": false,
    "valid": null,
    "valueMissing": false
  }
}

Use with other form controls

Select

Select your favourite fruit.

Checkbox

Fieldset

Address Information

We need your address to deliver your order.

Radio Group

Best apple

Choose your favourite apple.

Autocomplete

Choose your favourite fruit.

API Reference

ComponentDescription
FieldGroups all parts of the field. Renders a <div> element.
FieldLabelAn accessible label that is automatically associated with the field control. Renders a <label> element.
FieldControlThe form control to label and validate. Renders an <input> element. You can omit this part and use any Base UI input component instead. For example, Input, Checkbox, or Select, among others, will work with Field out of the box.
FieldDescriptionA paragraph with additional information about the field. Renders a <p> element.
FieldItemGroups individual items in a checkbox group or radio group with a label and description. Renders a <div> element.
FieldErrorAn error message displayed if the field control fails validation. Renders a <div> element.
FieldValidityUsed to display a custom message based on the field’s validity. Requires children to be a function that accepts field validity state as an argument.