Form Primitive
Form coordinates native constraints, custom and asynchronous validators, schema results, error visibility, and submission across its Fields. 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 Form anatomy with the Runtime wiring included.
---import { Form } from "@starwind-ui/astro/form";---
<Form.Root> <Form.ErrorSummary>Please fix the highlighted fields.</Form.ErrorSummary></Form.Root>Use the React primitive adapter when Form state participates in React rendering.
import { Form } from "@starwind-ui/react/form";
export function Example() { return ( <Form.Root> <Form.ErrorSummary>Please fix the highlighted fields.</Form.ErrorSummary> </Form.Root> );}Render the Form data-sw-* contract yourself, then initialize createForm.
<form data-sw-form data-slot="form"> <div data-sw-form-error-summary data-slot="form-error-summary" role="status" aria-live="polite" aria-atomic="true" hidden>Please fix the highlighted fields.</div></form>
<script type="module"> import { createForm } from "@starwind-ui/runtime/form";
const root = document.querySelector("[data-sw-form]"); if (root) { createForm(root); }</script>Validation policy values
validationTiming, revalidationTiming, and errorVisibility accept semantic change, blur, submit, or manual causes. change means each accepted value revision for native and Runtime controls. Before submission, only validationTiming is active; after a submission attempt, revalidationTiming replaces it. The defaults are validationTiming="submit", revalidationTiming="change", and errorVisibility="submit".
API Reference
Root
The main element that owns the Form Runtime instance.
- Default element
- form
- Discovery hook
- data-sw-form
- Role
- -
Props
data-error-visibility "blur" | "change" | "manual" | "submit" -
- Description
- Low-level errorVisibility form for semantic change, blur, submit, or manual validation; defaults to submit.
- 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; defaults to change.
- 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; defaults to submit.
- 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 errors; defaults to submit.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
revalidationTiming "blur" | "change" | "manual" | "submit" change
- Description
- After a Form submission attempt, replaces validationTiming with semantic change, blur, submit, or manual validation; defaults to change.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
validationTiming "blur" | "change" | "manual" | "submit" submit
- Description
- Selects semantic change, blur, submit, or manual validation before a Form submission attempt; defaults to submit.
- Kind
- option
- Targets
- root
- Full type
- "blur" | "change" | "manual" | "submit"
Data Attributes
Runtime hooks
Metadata
Error Summary
Summary of validation errors for Form.
- Default element
- div
- Discovery hook
- data-sw-form-error-summary
- Role
- -
Data Attributes
Runtime hooks
Metadata
Runtime API
- Factory
createForm- Import
@starwind-ui/runtime/form- Root hook
- root
data-sw-form - Option props
- -
Related Styled Components
Changelog
View version history v1.0.0 4 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.2.1
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
v0.2.0
- Replaced additive validation timing with before- and after-submit policies and added imperative validation, visibility, reset, and external-error APIs.
- Unified the previous input and committed-only change timings as change, which now runs for every accepted value revision.
v0.1.0
- Introduced native form coordination, validation timing, submission state, and field reset behavior.