Skip to main content

Starwind UI v3.0 is now available! Migration guide

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>

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

Prop Type Default Toggle
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.

  • dirty
  • setDirty
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.

  • touched
  • setTouched
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

State Type Props Toggle
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.

  • dirty
  • setDirty
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.

  • touched
  • setTouched
Runtime / HTML

call setTouched for later updates.

  • setTouched

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-dirty - Reflects the dirty state on the Root part.
data-invalid - Reflects the invalid state on the Root part.
data-touched - Reflects the touched state on the Root part.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Root part.
data-error-visibility - Reflects the error visibility prop on the Root part.
data-name - Reflects the name prop on the Root part.
data-revalidation-timing - Reflects the revalidation timing prop on the Root part.
data-validation-timing - Reflects the validation timing prop on the Root part.

Label

Text label associated with Field.

Default element
label
Discovery hook
data-sw-field-label
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field-label - Marks the Label part so Starwind Runtime can find it.

Control

Groups the interactive controls for Field.

Default element
input
Discovery hook
data-sw-field-control
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field-control - Marks the Control part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-sw-input - Identifies Control metadata for styling and selectors.

Description

Supporting description text for Field.

Default element
p
Discovery hook
data-sw-field-description
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field-description - Marks the Description part so Starwind Runtime can find it.

Item

An interactive item inside the Field collection.

Default element
div
Discovery hook
data-sw-field-item
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field-item - Marks the Item part so Starwind Runtime can find it.

Error

Error message content for Field.

Default element
div
Discovery hook
data-sw-field-error
Role
-

Props

Prop Type Default Toggle
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
Attribute Value Description
data-sw-field-error - Marks the Error part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-match - Reflects the match prop on the Error part.
data-message-source - Reflects the message source prop on the Error part.

Validity

Validation state container for Field.

Default element
div
Discovery hook
data-sw-field-validity
Role
-

Props

Prop Type Default Toggle
match FieldErrorMatch true
Description
Controls how Field filters matching items.
Kind
attribute
Targets
validity
Full type
FieldErrorMatch

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-field-validity - Marks the Validity part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-match - Reflects the match prop on the Validity part.

Runtime API

Factory
createField
Import
@starwind-ui/runtime/field
Root hook
root data-sw-field
Option props
dirty, disabled, invalid, name, touched

Runtime Setters

Method Target Description
setDirty prop: dirty Updates whether Field is dirty from Runtime code.
setDisabled prop: disabled Updates whether Field is disabled from Runtime code.
setInvalid prop: invalid Updates whether Field is invalid from Runtime code.
setName prop: name Updates the Field form field name from Runtime code.
setTouched prop: touched Updates whether Field is touched from Runtime code.
Component Relationship
Field Composite

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.