Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

This name appears on your profile.

Installation

Usage

For complete validation policies, custom and asynchronous validation, schema adapters, and submission flows using Field and FieldSet, see the Form examples.

Composition

Use Field for one control. Use FieldSet and FieldGroup for related controls.

FieldSet
├── FieldLegend
├── FieldDescription
└── FieldGroup
├── Field
│ ├── FieldLabel
│ ├── FieldControl
│ ├── FieldDescription
│ ├── FieldError
│ └── FieldValidity
├── FieldSeparator
└── Field
└── FieldItem
├── Checkbox or Radio
└── FieldContent
├── FieldLabel
└── FieldDescription

Field Names

Field passes its name to the control inside it, so the form submits the value under that name. A name on the control wins over the name on its Field, in every framework. For example, <Field name="fruit"><Select name="own" /></Field> submits own. Set the name in one place.

Groups and Non-input Controls

Use FieldSet with FieldLegend when several controls answer one question or belong to the same settings section. FieldItem gives checkboxes, radios, and other non-text controls the same label, description, validation, disabled-state, and layout conventions as text inputs.

Preferences

Receive occasional release notes.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Field

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
errorVisibility "blur" | "change" | "manual" | "submit" —
Description
Selects whether semantic change, blur, submit, or manual validation reveals errors; inherits the owning Form policy when omitted.
Classification
Primitive override
Primitive prop
field.Root.errorVisibility
orientation "horizontal" | "responsive" | "vertical" "vertical"
Description
Selects the horizontal or vertical layout direction.
Classification
Styled variant
revalidationTiming "blur" | "change" | "manual" | "submit" —
Description
After an owning Form submission attempt, replaces validationTiming with semantic change, blur, submit, or manual validation; inherits the owning Form policy when omitted.
Classification
Primitive override
Primitive prop
field.Root.revalidationTiming
validationTiming "blur" | "change" | "manual" | "submit" —
Description
Selects semantic change, blur, submit, or manual validation before an owning Form submission attempt; inherits the owning Form policy when omitted.
Classification
Primitive override
Primitive prop
field.Root.validationTiming

Field Legend

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
variant "label" | "legend" "legend"
Description
Selects the component's visual variant.
Classification
Styled variant

Field Group

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
variant "default" | "outline" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Field Label

Inherits label attributes.

Contains the following additional props:

Prop Type Default Toggle details
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant

Field Control

Inherits input attributes. Omits `children`, `defaultValue`, `size`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
defaultValue string | number | string[] —
Description
Sets the initial value when the component is uncontrolled.
Classification
Primitive override
Type imports
React import type { InputValue } from "@starwind-ui/react";
Primitive prop
field.Control.defaultValue
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
value string | number | string[] —
Description
Controls or identifies the component value.
Classification
Primitive override
Type imports
React import type { InputValue } from "@starwind-ui/react";
Primitive prop
field.Control.value

Field Error

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
match boolean | "badInput" | "customError" | "patternMismatch" | "rangeOverflow" | "rangeUnderflow" | "stepMismatch" | "tooLong" | "tooShort" | "typeMismatch" | "valid" | "valueMissing" —
Description
Selects the validation state that renders this message.
Classification
Primitive override
Primitive prop
field.Error.match

Field Validity

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
match boolean | "badInput" | "customError" | "patternMismatch" | "rangeOverflow" | "rangeUnderflow" | "stepMismatch" | "tooLong" | "tooShort" | "typeMismatch" | "valid" | "valueMissing" —
Description
Selects the validation state that renders this message.
Classification
Wrapper prop

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Field.

Runtime API

Field primitive
createField from @starwind-ui/runtime/field
Fieldset primitive
createFieldset from @starwind-ui/runtime/fieldset

Changelog

View version history v1.1.1 6 releases

v1.1.1

  • Field file inputs now keep their selected-file spacing on the reading end side.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v1.1.0

  • In Astro, an attribute that you set on FieldContent, FieldGroup, FieldSeparator, and FieldTitle now wins over the component’s own default for the same attribute, such as role or aria-label.
  • A name on a control now wins over the name on its Field, in all frameworks. If you set different names on a Field and its control, and your server reads the Field name, remove the name from the control.
  • In React, Select and Combobox inside a Field with a name now send their value when the form submits, and they call onValueChange, onOpenChange, and onInputValueChange. Before, the form often left the value out, and the callbacks did not run.
  • Inside a Field in Astro, Checkbox and Switch now clear when the form resets. Before, they stayed checked.
  • In Vue, a Boolean prop that you leave out, such as invalid, dirty, or touched, no longer becomes false. The default of the underlying component applies.
  • In Vue, FieldSeparator renders data-content, as in the other frameworks.
  • Field no longer loads Color Picker code unless the Field holds a Color Picker. If your page calls createField and imports no Runtime code for a control inside that Field, Field now loads the code for all ten controls it can hold, about 47 KB gzipped in total. To skip that, import the control’s own entry, such as @starwind-ui/runtime/select.

v1.0.3

  • When the first Field with an error holds a Select or Radio Group, Form submit and validate({ focus: true }) now put focus on the Select button or on a radio. A Radio Group puts focus on its checked radio when one is checked. Before, focus did not go to any control that the user could see.

v1.0.2

  • Fieldset keeps its accessible label linked to its current legend when that legend changes.
  • Form controls now load Field’s automatic setup code only when Field is used. Labels, validation, and native form behavior remain supported.

v1.0.1

  • The default export in index.ts now has a name, FieldParts, so framework tools show a clear name.

v1.0.0

  • Added Field and its parts, with validation, grouping, labels, descriptions, and messages that screen readers can read. They get their behavior from Starwind Runtime.
  • See the Field Primitive and Fieldset Primitive for the unstyled parts and the behavior API.