Field
A component that provides labeling and validation for form controls.
View as MarkdownVisible on your profile
Anatomy
Import the component and assemble its parts:
API reference
Root
Groups all parts of the field.
Renders a <div> element.
namestring—
- Name
- Description
Identifies the field when a form is submitted. Takes precedence over the
nameprop on the<Field.Control>component.- Type
actionsRefReact.RefObject<Field.Root.Actions | null>—
- Name
- Description
A ref to imperative actions.
validate: Validates the field when called.
- Type
dirtyboolean—
- Name
- Description
Whether the field’s value has been changed from its initial value. Useful when the field state is controlled by an external library.
- Type
touchedboolean—
- Name
- Description
Whether the field has been touched. Useful when the field state is controlled by an external library.
- Type
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction. Takes precedence over the
disabledprop on the<Field.Control>component.- Type
- Default
false
invalidboolean—
- Name
- Description
Whether the field is invalid. Useful when the field state is controlled by an external library.
- Type
validatefunction—
- Name
- Description
A function for custom validation. Return a string or an array of strings with the error message(s) if the value is invalid, or
nullif the value is valid. Asynchronous functions are supported, but they do not prevent form submission when usingvalidationMode="onSubmit".- Type
validationModeForm.ValidationMode'onSubmit'
- Name
- Description
Determines when the field should be validated. This takes precedence over the
validationModeprop on<Form>.onSubmit: triggers validation when the form is submitted, and re-validates on change after submission.onBlur: triggers validation when the control loses focus.onChange: triggers validation on every change to the control value.
- Type
- Default
'onSubmit'
validationDebounceTimenumber0
- Description
How long to wait between
validatecallbacks ifvalidationMode="onChange"is used. Specified in milliseconds.- Type
- Default
0
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the field is disabled.
data-valid
Present when the field is valid.
data-invalid
Present when the field is invalid.
data-dirty
Present when the field’s value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the field is disabled. | |
data-valid | Present when the field is valid. | |
data-invalid | Present when the field is invalid. | |
data-dirty | Present when the field’s value has changed. | |
data-touched | Present when the field has been touched. | |
data-filled | Present when the field is filled. | |
data-focused | Present when the field control is focused. | |
Field.Root.StateHide
Field.Root.ActionsHide
Label
An accessible label that is automatically associated with the field control.
Renders a <label> element.
nativeLabelbooleantrue
- Name
- Description
Whether the component renders a native
<label>element when replacing it via therenderprop. Set tofalseif the rendered element is not a label (for example,<div>).This is useful to avoid inheriting label behaviors on
<button>controls (such as<Select.Trigger>and<Combobox.Trigger>), including avoiding:hoveron the button when hovering the label, and preventing clicks on the label from firing on the button.- Type
- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in valid state.
data-invalid
Present when the field is in invalid state.
data-dirty
Present when the field’s value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the field is disabled. | |
data-valid | Present when the field is in valid state. | |
data-invalid | Present when the field is in invalid state. | |
data-dirty | Present when the field’s value has changed. | |
data-touched | Present when the field has been touched. | |
data-filled | Present when the field is filled. | |
data-focused | Present when the field control is focused. | |
Field.Label.StateHide
Control
The 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.
defaultValueUnion—
- Name
- Type
onValueChangefunction—
- Name
- Description
Callback fired when the
valuechanges. Use when controlled.- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in valid state.
data-invalid
Present when the field is in invalid state.
data-dirty
Present when the field’s value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the field is disabled. | |
data-valid | Present when the field is in valid state. | |
data-invalid | Present when the field is in invalid state. | |
data-dirty | Present when the field’s value has changed. | |
data-touched | Present when the field has been touched. | |
data-filled | Present when the field is filled. | |
data-focused | Present when the field control is focused. | |
Field.Control.StateHide
Field.Control.ChangeEventReasonHide
Field.Control.ChangeEventDetailsHide
Description
A paragraph with additional information about the field.
Renders a <p> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in valid state.
data-invalid
Present when the field is in invalid state.
data-dirty
Present when the field’s value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the field is disabled. | |
data-valid | Present when the field is in valid state. | |
data-invalid | Present when the field is in invalid state. | |
data-dirty | Present when the field’s value has changed. | |
data-touched | Present when the field has been touched. | |
data-filled | Present when the field is filled. | |
data-focused | Present when the field control is focused. | |
Field.Description.PropsHide
Re-Export of Description props as FieldDescriptionProps
Field.Description.StateHide
Item
Groups individual items in a checkbox group or radio group with a label and description.
Renders a <div> element.
disabledbooleanfalse
- Name
- Description
Whether the wrapped control should ignore user interaction. The
disabledprop on<Field.Root>takes precedence over this.- Type
- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Field.Item.StateHide
Error
An error message displayed if the field control fails validation.
Renders a <div> element.
matchUnion—
- Name
- Description
Determines whether to show the error message according to the field’s ValidityState. Specifying
truewill always show the error message, and lets external libraries control the visibility.- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the field is disabled.
data-valid
Present when the field is in valid state.
data-invalid
Present when the field is in invalid state.
data-dirty
Present when the field’s value has changed.
data-touched
Present when the field has been touched.
data-filled
Present when the field is filled.
data-focused
Present when the field control is focused.
data-starting-style
Present when the error message is animating in.
data-ending-style
Present when the error message is animating out.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the field is disabled. | |
data-valid | Present when the field is in valid state. | |
data-invalid | Present when the field is in invalid state. | |
data-dirty | Present when the field’s value has changed. | |
data-touched | Present when the field has been touched. | |
data-filled | Present when the field is filled. | |
data-focused | Present when the field control is focused. | |
data-starting-style | Present when the error message is animating in. | |
data-ending-style | Present when the error message is animating out. | |
Field.Error.StateHide
Validity
Used 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.
children*—
- Name
- Description
A function that accepts the field validity state as an argument.
- Type