Field Primitive
Field is a Starwind Runtime primitive in the field-control-coordinator contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
Anatomy
Use the Astro primitive adapter to render Field anatomy with the Runtime wiring included.
---import { Field } from "@starwind-ui/astro/field";---
<Field.Root> <Field.Label>Email</Field.Label> <Field.Control /> <Field.Description>Use your work email.</Field.Description> <Field.Error>Enter a valid email.</Field.Error></Field.Root>Use the React primitive adapter when Field state participates in React rendering.
import { Field } from "@starwind-ui/react/field";
export function Example() { return ( <Field.Root> <Field.Label>Email</Field.Label> <Field.Control /> <Field.Description>Use your work email.</Field.Description> <Field.Error>Enter a valid email.</Field.Error> </Field.Root> );}Render the Field data-sw-* contract yourself, then initialize createField.
<div data-sw-field> <label data-sw-field-label>Email</label> <input data-sw-field-control data-sw-input /> <p data-sw-field-description>Use your work email.</p> <div data-sw-field-error hidden>Enter a valid email.</div></div>
<script type="module"> import { createField } from "@starwind-ui/runtime/field";
const root = document.querySelector("[data-sw-field]"); if (root) { createField(root); }</script>Validation policy values
The timing props accept semantic change, blur, submit, or manual causes. Field values override the owning Form; otherwise they inherit its submit/change/submit defaults and post-submit replacement policy.
API Reference
Root
The main element that owns the Field Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-field
- Role
- -
Props
dirty boolean -
- Description
- Marks whether the field value has changed.
- Kind
- control
- Targets
- -
- Full type
- boolean
- React
Use dirty for controlled state.
dirty
- Astro
Use dirty for initial state and call setDirty for later updates.
dirtysetDirty
- Runtime / HTML
call setDirty for later updates.
setDirty
disabled boolean false
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
data-error-visibility "blur" | "change" | "manual" | "submit" -
- Description
- Low-level errorVisibility form for semantic change, blur, submit, or manual validation; overrides the owning Form for this Field.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
data-revalidation-timing "blur" | "change" | "manual" | "submit" -
- Description
- Low-level revalidationTiming form that replaces validationTiming after a submission attempt; overrides the owning Form for this Field.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
data-validation-timing "blur" | "change" | "manual" | "submit" -
- Description
- Low-level validationTiming form for semantic change, blur, submit, or manual validation before submission; overrides the owning Form for this Field.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
errorVisibility "blur" | "change" | "manual" | "submit" submit
- Description
- Selects whether semantic change, blur, submit, or manual validation reveals this Field's errors; inherits the owning Form policy when omitted.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
invalid boolean -
- Description
- Marks the field as invalid for validation styling and state.
- Kind
- control
- Targets
- -
- Full type
- boolean
name string -
- Description
- Sets the submitted form field name.
- Kind
- option
- Targets
- -
- Full type
- string
revalidationTiming "blur" | "change" | "manual" | "submit" change
- Description
- After an owning Form submission attempt, replaces validationTiming with semantic change, blur, submit, or manual validation; inherits the owning Form policy when omitted.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
touched boolean -
- Description
- Marks whether the field has been visited.
- Kind
- control
- Targets
- -
- Full type
- boolean
- React
Use touched for controlled state.
touched
- Astro
Use touched for initial state and call setTouched for later updates.
touchedsetTouched
- Runtime / HTML
call setTouched for later updates.
setTouched
validationTiming "blur" | "change" | "manual" | "submit" submit
- Description
- Selects semantic change, blur, submit, or manual validation before an owning Form submission attempt; inherits the owning Form policy when omitted.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
State
dirty boolean dirty
- Description
- Tracks whether the Field value has changed.
- Initial attribute
- -
- Runtime getter
- -
- Runtime setter
- setDirty
- React
Use dirty for controlled state.
dirty
- Astro
Use dirty for initial state and call setDirty for later updates.
dirtysetDirty
- Runtime / HTML
call setDirty for later updates.
setDirty
touched boolean touched
- Description
- Tracks whether Field has been visited.
- Initial attribute
- -
- Runtime getter
- -
- Runtime setter
- setTouched
- React
Use touched for controlled state.
touched
- Astro
Use touched for initial state and call setTouched for later updates.
touchedsetTouched
- Runtime / HTML
call setTouched for later updates.
setTouched
Data Attributes
Runtime hooks
State
Metadata
Label
Text label associated with Field.
- Default element
- label
- Discovery hook
- data-sw-field-label
- Role
- -
Data Attributes
Runtime hooks
Control
Groups the interactive controls for Field.
- Default element
- input
- Discovery hook
- data-sw-field-control
- Role
- -
Data Attributes
Runtime hooks
Metadata
Description
Supporting description text for Field.
- Default element
- p
- Discovery hook
- data-sw-field-description
- Role
- -
Data Attributes
Runtime hooks
Item
An interactive item inside the Field collection.
- Default element
- div
- Discovery hook
- data-sw-field-item
- Role
- -
Data Attributes
Runtime hooks
Error
Error message content for Field.
- Default element
- div
- Discovery hook
- data-sw-field-error
- Role
- -
Props
match FieldErrorMatch false
- Description
- Controls how Field filters matching items.
- Kind
- attribute
- Targets
- error
- Full type
- FieldErrorMatch
messageSource "children" | "validation" -
- Description
- Sets the message source attribute on the Error part.
- Kind
- attribute
- Targets
- error
- Full type
- "children" | "validation"
Data Attributes
Runtime hooks
Metadata
Validity
Validation state container for Field.
- Default element
- div
- Discovery hook
- data-sw-field-validity
- Role
- -
Props
match FieldErrorMatch true
- Description
- Controls how Field filters matching items.
- Kind
- attribute
- Targets
- validity
- Full type
- FieldErrorMatch
Data Attributes
Runtime hooks
Metadata
Runtime API
- Factory
createField- Import
@starwind-ui/runtime/field- Root hook
- root
data-sw-field - Option props
- dirty, disabled, invalid, name, touched
Runtime Setters
Related Styled Components
Changelog
View version history v1.0.0 3 releases
v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
v0.1.1
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
v0.1.0
- Introduced field labels, descriptions, validation state, and accessible message coordination.