Field
This name appears on your profile.
---import { Field, FieldControl, FieldDescription, FieldError, FieldLabel, FieldValidity,} from "@/components/starwind/field";---
<Field name="displayName"> <FieldLabel>Display name</FieldLabel> <FieldControl required minlength="2" /> <FieldDescription>This name appears on your profile.</FieldDescription> <FieldError match="valueMissing">Enter a display name.</FieldError> <FieldError match="tooShort">Use at least two characters.</FieldError> <FieldValidity match="valid">Looks good.</FieldValidity></Field>import { Field, FieldControl, FieldDescription, FieldError, FieldLabel, FieldValidity,} from "@/components/starwind/field";
export function Example() { return ( <Field name="displayName"> <FieldLabel>Display name</FieldLabel> <FieldControl required minLength={2} /> <FieldDescription>This name appears on your profile.</FieldDescription> <FieldError match="valueMissing">Enter a display name.</FieldError> <FieldError match="tooShort">Use at least two characters.</FieldError> <FieldValidity match="valid">Looks good.</FieldValidity> </Field> );}<script setup lang="ts">import { Field, FieldControl, FieldDescription, FieldError, FieldLabel, FieldValidity,} from "@/components/starwind/field";</script>
<template> <Field name="displayName"> <FieldLabel>Display name</FieldLabel> <FieldControl required minlength="2" /> <FieldDescription>This name appears on your profile.</FieldDescription> <FieldError match="valueMissing">Enter a display name.</FieldError> <FieldError match="tooShort">Use at least two characters.</FieldError> <FieldValidity match="valid">Looks good.</FieldValidity> </Field></template><script lang="ts"> import { Field, FieldControl, FieldDescription, FieldError, FieldLabel, FieldValidity, } from "@/components/starwind/field";</script>
<div class="w-full max-w-md"> <Field name="displayName"> <FieldLabel>Display name</FieldLabel> <FieldControl required minlength={2} placeholder="Ada Lovelace" /> <FieldDescription>This name appears on your profile.</FieldDescription> <FieldError match="valueMissing">Enter a display name.</FieldError> <FieldError match="tooShort">Use at least two characters.</FieldError> <FieldValidity match="valid">Looks good.</FieldValidity> </Field></div>Installation
pnpx starwind@latest add field --framework astronpx starwind@latest add field --framework astroyarn dlx starwind@latest add field --framework astropnpx starwind@latest add field --framework reactnpx starwind@latest add field --framework reactyarn dlx starwind@latest add field --framework reactpnpx starwind@latest add field --framework vuenpx starwind@latest add field --framework vueyarn dlx starwind@latest add field --framework vuepnpx starwind@latest add field --framework sveltenpx starwind@latest add field --framework svelteyarn dlx starwind@latest add field --framework svelteUsage
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 └── FieldDescriptionField 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.
---import { Checkbox } from "@/components/starwind/checkbox";import { Field, FieldGroup, FieldItem, FieldLabel, FieldLegend, FieldSet,} from "@/components/starwind/field";---
<FieldSet> <FieldLegend>Preferences</FieldLegend> <FieldGroup> <Field name="updates" orientation="horizontal"> <FieldItem> <Checkbox id="field-updates" value="yes" /> <FieldLabel for="field-updates">Product updates</FieldLabel> </FieldItem> </Field> </FieldGroup></FieldSet>import { Checkbox } from "@/components/starwind/checkbox";import { Field, FieldGroup, FieldItem, FieldLabel, FieldLegend, FieldSet } from "@/components/starwind/field";
export function Example() { return ( <> <FieldSet> <FieldLegend>Preferences</FieldLegend> <FieldGroup> <Field name="updates" orientation="horizontal"> <FieldItem> <Checkbox id="field-updates" value="yes" /> <FieldLabel htmlFor="field-updates">Product updates</FieldLabel> </FieldItem> </Field> </FieldGroup> </FieldSet> </> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";import { Field, FieldGroup, FieldItem, FieldLabel, FieldLegend, FieldSet,} from "@/components/starwind/field";</script>
<template> <FieldSet> <FieldLegend>Preferences</FieldLegend> <FieldGroup> <Field name="updates" orientation="horizontal"> <FieldItem> <Checkbox id="field-updates" value="yes" /> <FieldLabel for="field-updates">Product updates</FieldLabel> </FieldItem> </Field> </FieldGroup> </FieldSet></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox"; import { Field, FieldGroup, FieldItem, FieldLabel, FieldLegend, FieldSet, } from "@/components/starwind/field";</script>
<FieldSet> <FieldLegend>Preferences</FieldLegend> <FieldGroup> <Field name="updates" orientation="horizontal"> <FieldItem> <Checkbox id="field-updates" value="yes" /> <FieldLabel for="field-updates">Product updates</FieldLabel> </FieldItem> </Field> </FieldGroup></FieldSet>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:
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:
variant "label" | "legend" "legend"
- Description
- Selects the component's visual variant.
- Classification
- Styled variant
Field Group
Inherits div attributes.
Contains the following additional props:
variant "default" | "outline" "default"
- Description
- Selects the component's visual variant.
- Classification
- Styled variant
Field Label
Inherits label attributes.
Contains the following additional props:
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:
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:
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:
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.
Primitive API
Runtime API
- Field primitive
createFieldfrom@starwind-ui/runtime/field- Fieldset primitive
createFieldsetfrom@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, andFieldTitlenow wins over the component’s own default for the same attribute, such asroleoraria-label. - A
nameon a control now wins over thenameon itsField, in all frameworks. If you set different names on aFieldand its control, and your server reads theFieldname, remove thenamefrom the control. - In React, Select and Combobox inside a
Fieldwith anamenow send their value when the form submits, and they callonValueChange,onOpenChange, andonInputValueChange. Before, the form often left the value out, and the callbacks did not run. - Inside a
Fieldin 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, ortouched, no longer becomesfalse. The default of the underlying component applies. - In Vue,
FieldSeparatorrendersdata-content, as in the other frameworks. - Field no longer loads Color Picker code unless the Field holds a Color Picker. If your page calls
createFieldand 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.tsnow 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.