Skip to main content

A form field wrapper that provides accessible labeling, helper and error text, validation state and indicators for form inputs.

Choose a unique username for your account.

Read more about installing Components and Primitives.

An empty required field stays quiet until the user has edited it or submitted the form.

Helper text sits below the input and is linked to it with aria-describedby.

Must be at least 8 characters long.

Set invalid to show the error text, for example for a rule your backend decides.

The password must be at least 8 characters long.

disabled on the field disables the control inside it.

A required checkbox counts as missing until it is checked, for example "I accept the terms and conditions". The same goes for a required Select, Combobox, RadioGroup or CheckboxGroup while nothing is chosen.

The field reads the ValidityState of its control, so the constraints you already know are the rules: required as a prop of the field, and type="email", pattern, min, max, step, minlength and maxlength as plain attributes on the input part. The constraints other than required come from a native input or textarea. An Input or Textarea with a maxLengthBehavior of Invalid reports tooLong as well.

The form renders novalidate, which hands the display of errors to your error texts. An error text without a match shows the browser's message for the failed constraint. Give it a match to show your own text for exactly that constraint: valueMissing, typeMismatch, patternMismatch, tooShort, tooLong, rangeUnderflow, rangeOverflow, stepMismatch, badInput or customError.

Five digits.

validationMode decides when a field validates and shows its errors. Set it on the form for all its fields, or on a single field:

A submit validates all fields in every mode, shows every error and moves the focus to the first invalid one. While a mouse button or finger is down, error texts and indicators wait for the release. Keyboard users get them right away.

Errors show when you leave an edited field, and update while you type.
Errors show when you leave an edited field.
Errors show while you type.
Errors show when you submit.

An indicator shows its content while the field is in the state given by its type: required, invalid, valid or validating. valid appears once the field has been validated and passed.

At least three lowercase letters, digits or underscores.

Ask the server whether a username is still free: pass a validate function that returns a message (or a list of messages) to mark the field invalid, and null to accept the value. It can return a promise. While the request runs, the validating indicator shows and a submit waits for the result. A result for a value the user has changed meanwhile is dropped.

A function cannot be rendered into markup, so pass validate from TypeScript: render the field with autoMount="{false}" and mount it in your entry file. validate receives the value and a snapshot of the native validity. It runs where the validation mode lets errors show (on blur by default), which makes it a good place for a request.

Try "admin" or "ada".

Replace the function later with updateProps({ validate }). Errors from the Form schema or callback and from the server (a 422 or onSubmit) reach the field on their own and show in the same error text.

Add listenTo="{0: 'password'}" to the passwordConfirm field. It names the sibling fields to watch, so when password changes, passwordConfirm validates again and its result stays current.

Put both rules in a validation callback, see Manual Client-Side Validation. A Zod .refine() on the whole schema runs after every field passes its own rule, so the mismatch error would wait for the length rule.

At least 8 characters.

Whenever a field named in listenTo changes, the root of the listening field dispatches fluid-primitives:field:dependencychange. addDependencyChangeListener() on the field handle subscribes to it and returns a function that removes the listener. listenTo takes several names, e.g. listenTo="{0: 'arrival', 1: 'departure'}".

This shows a studentId field with listenTo="{0: 'ticketType'}" when the ticket type is student:

The callback receives dependencies (the value of each listened field, keyed by name) and values, the FormValues of the whole form. The event registration example in the Forms guide shows it in a working form.

Every part renders the state of the field as data attributes, so a label, an indicator or an error text can be styled with CSS alone. The API reference lists them per part.

From TypeScript, field.api and the FieldHandle of form.api.getField(name) expose the same flags: touched, dirty, filled, focused, valid, invalid, validating, disabled, required, readOnly and errors, together with validate(), clearErrors() and reset(). The root dispatches fluid-primitives:field:valuechange once a value has settled, 100 ms after the last keystroke by default.

The following tables cover the available props of the Fluid Primitives.

Provides shared field state for labels, helper text, errors, indicators and controls. Renders a <div> element.

NameDescriptionRequiredDefault
namestring
The unique field name used to associate labels, helper text, errors, and form values.
Yes
-
disabledboolean
Whether the field is disabled. A field inside a disabled `<fieldset>` is disabled as well.
No
-
invalidboolean
Whether the field is invalid, regardless of validation. Use it for errors the browser's constraint validation and the form's validation cannot compute, e.g. a pre-populated server error.
No
-
requiredboolean
Whether the field is required. An empty required field stays quiet until the user edits it or the form is submitted.
No
-
readOnlyboolean
Whether the field is read-only.
No
-
defaultValuemixed
The initial value that child controls can use when rendered inside the field.
No
-
validationModeEnum\ValidationMode
When errors become visible. `auto` validates on blur once the value was edited and on every change while an error shows, `onBlur` only on blur, `onChange` on every change, `onSubmit` only on submit. A submit validates every field in every mode. Without one, the field follows the `validationMode` of its form, which defaults to `auto`.
No
-
listenTostring[]
Names of sibling fields within the same form whose value changes this field should react to. Dispatches a `fluid-primitives:field:dependencychange` event on this field's root element (see `addDependencyChangeListener()`) on every value change of a listened-to field, and treats that like a change of this field itself, so it revalidates under the same rules as when its own value changes - e.g. a `passwordConfirm` field listening to `password`.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
providerstring
The `id` of the `.provider` this root takes its `rootId` and props from.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.
data-nameThe name of the field.

Labels the associated form control. Renders a <label> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.

Wraps the slotted form control and wires up shared field attributes. Renders the element defined by the asChild prop.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.

Displays help or supporting text for the field. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.

Displays the validation message of the field, or the text of its match when one constraint failed. Renders a <div> element.

NameDescriptionRequiredDefault
matchEnum\ValidityMatch
Narrows the error text to one failed native constraint, e.g. `valueMissing` or `typeMismatch`. Without it the text shows whenever the field is invalid and displays the error messages; with it the slotted text is shown as is.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.

Shows its content while the field is in the state given by type: required, invalid, valid or validating. Renders a <span> element.

NameDescriptionRequiredDefault
typeEnum\FieldIndicatorType
The state the indicator reflects: `required`, `invalid`, `valid` or `validating`. It stays in the DOM and is hidden unless the state matches, so CSS transitions survive.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when the field is disabled, or it is inside a disabled fieldset.
data-invalidPresent when the field is invalid: a native constraint failed, or `validate`, the form or the server reported an error.
data-validPresent when the field has been validated and passed.
data-requiredPresent when the field is required.
data-readonlyPresent when the field is read-only.
data-touchedPresent once the user has left the field at least once.
data-dirtyPresent when the value differs from the one the field started with. It goes away again when the user reverts the edit.
data-filledPresent when the field has a value.
data-focusPresent when focus is inside the field.
data-typeThe state the indicator reflects. One of: "required", "invalid", "valid", "validating".
NameDescriptionDefault
namestring
The name of the field. It keys the field in its form and is what the field's value is read by.
-
defaultValueunknown | undefined
The initial value, used while the DOM holds no control for this name yet.
-
listenTostring[] | undefined
Names of sibling fields in the same form whose value changes this field reacts to.
-
idsElementIds | undefined
The ids of the elements. Useful for composition.
-
disabledboolean | undefined
Whether the field is disabled. Also inherited from a surrounding native <fieldset disabled>.
invalidboolean | undefined
Whether the field is invalid, regardless of computed validity. Use for app-level errors (e.g. server errors) the machine cannot compute itself.
-
dirtyboolean | undefined
Whether the field's value has been changed from its initial value. Useful when the field state is controlled by an external library.
-
touchedboolean | undefined
Whether the field has been touched. Useful when the field state is controlled by an external library.
-
readOnlyboolean | undefined
Whether the field is read-only.
requiredboolean | undefined
Whether the field is required.
validate((details: ValidateDetails) => ValidateResult | Promise<ValidateResult>) | undefined
Custom validation, run against the value and the native validity snapshot. May return a promise; a newer validation run supersedes an in-flight one.
-
validationModeValidationMode | undefined
When validation results become visible. Without one, the field follows the validationMode of its form, and validates as auto outside a form.
"auto"
onValidityChange((details: ValidityChangeDetails) => void) | undefined
Called when the committed validity changes.
-
dir"ltr" | "rtl" | undefined
The document's text/writing direction.
"ltr"
idstring
The unique identifier of the machine.
-
getRootNode(() => ShadowRoot | Document | Node) | undefined
A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.
-
NameTypeDescription
idsResolvedElementIdsThe resolved element ids, for composition with other components.
disabledbooleanWhether the field is disabled (including inherited fieldset disabled state).
invalidbooleanWhether the field is invalid.
validboolean | nullCommitted validity: null until validation has run.
requiredbooleanWhether the field is required.
readOnlybooleanWhether the field is read-only.
focusedbooleanWhether the control is focused.
touchedbooleanWhether the control has been blurred at least once.
dirtybooleanWhether the value differs from the initial value.
filledbooleanWhether the control has a non-empty value.
validatingbooleanWhether an async validation is in flight.
errorsstring[]The committed error messages.
validityValiditySnapshot | nullThe committed validity snapshot, null until validation has run.
ariaDescribedbystring | undefinedThe composed aria-describedby, for wiring custom controls.
validateVoidFunctionRuns validation now, surfacing valueMissing even on a pristine field.
clearErrorsVoidFunctionClears committed errors and returns validity to the pristine (unvalidated) state.
resetVoidFunctionResets interaction state and validity to pristine.
getRootState() => RootStateReturns the state of the root.
getLabelState() => LabelStateReturns the state of the label.
getControlState() => ControlStateReturns the state of the control (input, textarea, select, or a custom host).
getHelperTextState() => HelperTextStateReturns the state of the helper text.
getErrorTextState(props?: ErrorTextProps) => ErrorTextStateReturns the state of the error text.
getIndicatorState(props: IndicatorProps) => IndicatorStateReturns the state of the indicator.
namestringThe name of the field.
getValue() => FieldValueThe current value of the field.
getErrorText() => string | nullThe first error message of the field, null if there is none.
getRootEl() => HTMLElement | nullThe root element of the field.
getFormMachine() => FormMachine | undefinedThe machine of the form the field sits in, undefined outside of a form.
setDisabled(disabled: boolean) => voidDisables or enables the field.
setRequired(required: boolean) => voidMarks the field as required or optional.
setReadOnly(readOnly: boolean) => voidMakes the field read-only or editable.
setConstraint(constraint: FieldConstraint | null) => voidRegisters a rule only the control inside the field knows, such as a soft maxLength. The field runs it with the value on every validation, and a violation makes the field invalid like a native constraint does. A field has one, a new one replaces the old, null takes it back.
addDependencyChangeListener(callback: (detail: FieldDependencyChangeDetail) => void) => () => voidCalls callback whenever the value of a field named in the listenTo prop of this field changes. Returns a function that removes the listener again. For a field without listenTo it never fires, but the returned function is still safe to call.