Field

Field is a component used to group form elements with label, helper message, error message, etc.

Usage

import { Field } from "@yamada-ui/react"
<Field.Root>
  <Field.Label />
  <Field.HelperMessage />
  <Field.ErrorMessage />
</Field.Root>

Displaying a Helper Message

To display a helper message, set a ReactNode to helperMessage.

We'll never share your email.

Alternatively, you can customize using Field.HelperMessage.

We'll never share your email.

Displaying an Error Message

To display an error message, set invalid to true and assign a ReactNode to errorMessage.

Email is required.

Alternatively, you can customize using Field.ErrorMessage.

Email is required.

Replacing Helper and Error Messages

Error messages are only displayed when invalid is true. To replace the helper message with the error message when the error message is displayed, set replace to true. By default, it is set to true.

Email is required.
We'll never share your email.Email is required.

Required

To make it required, set required to true.

We'll never share your email.

Disable

To disable, set disabled to true.

We'll never share your email.

Read-Only

To make it read-only, set readOnly to true.

We'll never share your email.

Change Direction

To change the direction, set orientation to "horizontal" or "vertical". By default, "vertical" is set.

We'll never share your email.
We'll never share your email.

Customize the Label

To customize the label, use Field.Label.

Customize the Required Indicator

To customize the required indicator, set a ReactNode to requiredIndicator.

Use Optional Indicator

To use an optional indicator, set a ReactNode to optionalIndicator.

Props

Accessibility

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
FieldRequiredIndicatorrole="presentation"Indicates that this is a presentation element.
aria-hiddenExcludes the element from the accessibility tree.
Field.ErrorMessagearia-live="polite"Indicates that it may be updated outside of focus.