base-ui-svelte

Field

A form control with label, description, and validation messaging.

View as Markdown

We will not share your email.

API Reference

Props mirror Base UI React where applicable, adapted for Svelte 5. Native HTML attributes for the rendered element are also accepted unless noted.

Field.Root

Extends div HTML attributes.

PropertyTypeDefaultDescription
namestring | undefined
disabledbooleanfalseWhether the control ignores user interaction.
invalidboolean | undefined
validate| ((value: string) => string | string[] | null | Promise<string | string[] | null>) | undefined
validationModeFieldValidationMode
childrenSnippet< [ { disabled: boolean; touched: boolean; dirty: boolean; focused: boolean; filled: boolean; valid: boolean | null; }, ] >Content rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Control

Extends input HTML attributes.

PropertyTypeDefaultDescription
disabledboolean | undefinedfalseWhether the control ignores user interaction.
valuestring | undefinedControlled value.
defaultValuestringUncontrolled initial value.
onValueChange((value: string, event: Event) => void) | undefinedEvent handler called when the value changes.
childrenSnippetContent rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Description

Extends paragraph HTML attributes.

PropertyTypeDefaultDescription
childrenSnippetContent rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Error

Extends div HTML attributes.

PropertyTypeDefaultDescription
matchFieldErrorMatch | undefinedWhen `true`, always show. When a `ValidityState` key, show when that flag is true. When omitted, show when the field is invalid (or has a form error).
childrenSnippet<[{ error: string }]>Content rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Item

Extends div HTML attributes.

PropertyTypeDefaultDescription
renderstringHTML element tag to render instead of the default host element.
disabledbooleanfalseWhether the control ignores user interaction.
childrenSnippetContent rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Label

Extends label HTML attributes.

PropertyTypeDefaultDescription
childrenSnippetContent rendered inside the part.
Data attributeDescription
data-dirtyPresent when the field value has changed.
data-disabledPresent when the part is disabled.
data-filledPresent when the field has a value.
data-focusedPresent when the field is focused.
data-invalidPresent when the field is invalid.
data-touchedPresent when the field has been touched.
data-validPresent when the field is valid.

Field.Validity

PropertyTypeDefaultDescription
childrenSnippet<[FieldValidityState]>Content rendered inside the part.