structyl

The full prop reference for the Form component. A form with declarative validation built on native ValidityState.

Import

tsx
import { Form } from '@structyl/styled';

Props

Form.Root

The root form element that manages field validation state and provides context to child components

PropTypeDefault
asChild#boolean

Render as a child element instead of native form; pass a single React element child

onClearServerErrors#() => void

Callback fired when the form changes, typically used to clear server-side validation errors

className#string

CSS class name (styled version applies 'flex flex-col gap-4' by default)

onInvalid#(event: Event) => void

HTML form onInvalid handler (preventDefault is composed automatically)

onChange#(event: ChangeEvent<HTMLFormElement>) => void

HTML form onChange handler (onClearServerErrors is composed automatically)

Form.Field

Container for a form field that associates label, control, and message elements

PropTypeDefault
asChild#boolean

Render as a child element instead of native div

name#string

Field name; required and must match the input name

serverInvalid#boolean

Flag to mark field as invalid from server-side validation (shows error message)

false
className#string

CSS class name (styled version applies 'flex flex-col gap-1.5' by default)

Form.Label

Label element automatically associated with the field's input control via htmlFor

PropTypeDefault
asChild#boolean

Render as a child element instead of native label

className#string

CSS class name (styled version applies text-sm font-medium and disabled styling)

Form.Control

Input element that tracks validation state and integrates with form validation

PropTypeDefault
asChild#boolean

Render as a child element instead of native input

className#string

CSS class name (styled version applies border, focus, and invalid state styling)

aria-invalid#boolean

Auto-set based on validity state or serverInvalid flag; reflects HTML5 validation

aria-describedby#string

Auto-set to message element ID for accessibility

type#string

HTML input type (e.g., 'text', 'email', 'number', 'password')

required#boolean

HTML5 validation: field is required

disabled#boolean

Disable the input element

pattern#string

HTML5 validation: regex pattern for input value

minLength#number

HTML5 validation: minimum string length

maxLength#number

HTML5 validation: maximum string length

min#string | number

HTML5 validation: minimum value for number/date inputs

max#string | number

HTML5 validation: maximum value for number/date inputs

step#string | number

HTML5 validation: step value for number/date inputs

placeholder#string

Placeholder text shown when input is empty

onChange#(event: ChangeEvent<HTMLInputElement>) => void

Change event handler (validity state is tracked automatically)

ref#React.Ref<HTMLInputElement>

Forward ref to underlying HTML input element

Form.Message

Validation error message element that displays based on field validity or server errors

PropTypeDefault
asChild#boolean

Render as a child element instead of native span

match#'badInput' | 'patternMismatch' | 'rangeOverflow' | 'rangeUnderflow' | 'stepMismatch' | 'tooLong' | 'tooShort' | 'typeMismatch' | 'valid' | 'valueMissing' | string | ((value: string, formData: FormData) => boolean | Promise<boolean>)

Validity matcher: show message when this HTML5 validation state or custom matcher matches

forceMatch#boolean

Force message to display even if validity doesn't match

children#React.ReactNode

Message content; if omitted, shows default message for HTML5 validity matchers

className#string

CSS class name (styled version applies 'text-destructive text-xs')

Form.ValidityState

Render prop component that provides the current field's HTML5 ValidityState for custom UI

PropTypeDefault
children#(validity: ValidityState | undefined) => React.ReactNode

Render function receiving the field's ValidityState object or undefined

Form.Submit

Submit button element (HTML type='submit' automatically set)

PropTypeDefault
asChild#boolean

Render as a child element instead of native button

className#string

CSS class name for styling

disabled#boolean

Disable the button

onClick#(event: React.MouseEvent<HTMLButtonElement>) => void

Click event handler

type#'submit'

Button type (automatically set to 'submit', overridable via props)

'submit'

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library