Implementation guide
Headless React Field Validation Guide
Use a headless field hook with shadcn/ui, HeroUI, or a custom control while retaining your existing markup, styles, and accessibility decisions.
By Tushar Khadde · Published · Updated
The mistake this stops
Adding validation forces a team to replace the controls and design system it already owns.
Async-safe field state, accessible error wiring, and typed failure reporting while the control remains yours.
Read the useBollardField component docs for its live preview, API, accessibility notes, dependencies, and limitations.
React example: useBollardField
Install the component, connect it to the action in your app, and keep the server responsible for validating and authorizing the request.
use-bollard-field.tsx23 lines
import { useBollardField } from "@/components/ui/use-bollard-field"
export function EmailField() {
const email = useBollardField({
initialValue: "",
validate: (value) => /.+@.+\..+/.test(value)
? undefined
: "Enter a valid email address.",
})
return (
<label>
Work email
<input
value={email.value}
onChange={(event) => email.setValue(event.target.value)}
onBlur={email.onBlur}
{...email.ariaProps}
/>
{email.error && <span id={email.errorId} role="alert">{email.error}</span>}
</label>
)
}Install the component
Use it safely
- Install the hook and connect value, blur, and aria props to your existing control.
- Use your current validator or schema adapter for the rule itself.
- Map server errors back with setError and keep the server as the source of truth.