Field
This name appears on your public 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> );}Runtime example adjustment
Field now coordinates native constraint validation and Runtime-backed controls. Match messages to validity states instead of writing page-local validation listeners.
Installation
pnpx starwind@latest add fieldnpx starwind@latest add fieldyarn dlx starwind@latest add fieldFramework Availability
Astro Available React AvailableField is available for Astro and React.
Usage
Groups and non-input controls
<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 Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.
Field
Inherits div attributes.
Contains the following additional props:
errorVisibility import("@starwind-ui/runtime/form").FormValidationTiming —
- Description
- Overrides when errors become visible for controls coordinated by this Field.
- Classification
- Wrapper prop
orientation "horizontal" | "responsive" | "vertical" "vertical"
- Description
- Selects the horizontal or vertical layout direction.
- Classification
- Styled variant
revalidationTiming import("@starwind-ui/runtime/form").FormValidationTiming —
- Description
- Selects when a previously validated field is validated again.
- Classification
- Wrapper prop
validationTiming import("@starwind-ui/runtime/form").FormValidationTiming —
- Description
- Selects when validation first runs.
- Classification
- Wrapper prop
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
- Wrapper prop
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
- Wrapper prop
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
v1.0.0
- Added the Runtime-backed Field family with validation, grouping, labels, descriptions, and accessible messages.
- See the Field Primitive and Fieldset Primitive for the underlying unstyled anatomy and behavior API.