Skip to content

Field

A component that provides labeling and validation for form controls.

Visible on your profile

Anatomy

Import the component and assemble its parts:

vue
<script setup>
import {
  FieldControl,
  FieldDescription,
  FieldError,
  FieldItem,
  FieldLabel,
  FieldRoot,
  FieldValidity,
} from 'base-ui-vue'
</script>

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

API reference

Root

Groups all parts of the field. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node.
namestring--Identifies the field when a form is submitted. Takes precedence over the name prop on <FieldControl>.
disabledbooleanfalseWhether the component should ignore user interaction. Takes precedence over the disabled prop on <FieldControl>.
invalidboolean--Whether the field is invalid. Useful when the field state is controlled by an external library.
dirtyboolean--Whether the field's value has been changed from its initial value. Useful when the field state is controlled by an external library.
touchedboolean--Whether the field has been touched. Useful when the field state is controlled by an external library.
validate(value, formValues) => string | string[] | null | Promise<...>--A function for custom validation. Return a string or array of strings for invalid values, or null for valid values.
validationMode'onSubmit' | 'onBlur' | 'onChange''onSubmit'Determines when the field should be validated. Takes precedence over the validationMode prop on <Form>.
validationDebounceTimenumber0How long to wait between validate callbacks if validationMode="onChange" is used. Specified in milliseconds.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
ExposesTypeDescription
validate() => voidValidates the field when called via a component ref.
AttributeDescription
data-disabledPresent when the field is disabled.
data-validPresent when the field is valid.
data-invalidPresent when the field is invalid.
data-dirtyPresent when the field's value has changed.
data-touchedPresent when the field has been touched.
data-filledPresent when the field is filled.
data-focusedPresent when the field control is focused.

Label

An accessible label that is automatically associated with the field control. Renders a <label> element.

PropTypeDefaultDescription
asstring | Component'label'The element or component to render.
nativeLabelbooleantrueWhether the component renders a native <label> element. Set to false when rendering a non-label element.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
AttributeDescription
data-disabledPresent when the field is disabled.
data-validPresent when the field is in valid state.
data-invalidPresent when the field is in invalid state.
data-dirtyPresent when the field's value has changed.
data-touchedPresent when the field has been touched.
data-filledPresent when the field is filled.
data-focusedPresent when the field control is focused.

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.

PropTypeDefaultDescription
asstring | Component'input'The element or component to render.
defaultValuestring''The initial uncontrolled value.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
EmitsTypeDescription
valueChange(value: string, event: Event)Fired when the value changes. Use when controlled.
AttributeDescription
data-disabledPresent when the field is disabled.
data-validPresent when the field is in valid state.
data-invalidPresent when the field is in invalid state.
data-dirtyPresent when the field's value has changed.
data-touchedPresent when the field has been touched.
data-filledPresent when the field is filled.
data-focusedPresent when the field control is focused.

Description

A paragraph with additional information about the field. Renders a <p> element.

PropTypeDefaultDescription
asstring | Component'p'The element or component to render.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
AttributeDescription
data-disabledPresent when the field is disabled.
data-validPresent when the field is in valid state.
data-invalidPresent when the field is in invalid state.
data-dirtyPresent when the field's value has changed.
data-touchedPresent when the field has been touched.
data-filledPresent when the field is filled.
data-focusedPresent when the field control is focused.

Item

Groups individual items in a checkbox group or radio group with a label and description. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the item node.
disabledbooleanfalseWhether the wrapped control should ignore user interaction. The disabled prop on <FieldRoot> takes precedence over this.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.

Error

An error message displayed if the field control fails validation. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to render.
matchboolean | keyof ValidityState--Determines whether to show the error message according to the field's ValidityState. Specifying true will always show the error message and lets external libraries control the visibility.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
AttributeDescription
data-disabledPresent when the field is disabled.
data-validPresent when the field is in valid state.
data-invalidPresent when the field is in invalid state.
data-dirtyPresent when the field's value has changed.
data-touchedPresent when the field has been touched.
data-filledPresent when the field is filled.
data-focusedPresent when the field control is focused.

Validity

Used to display a custom message based on the field's validity.

SlotsTypeDescription
validityValidityStateThe field validity state.
errorstringThe first error message.
errorsstring[]All error messages.
valueunknownThe current field value.
initialValueunknownThe initial field value.
transitionStatusTransitionStatusThe current transition status for the invalid state.