useBollardField is a copy-paste React component that prevents costly form mistakes before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.
- Headless · any React UI
- React 19+
- MIT licensed
- No extra npm packages
- A11y guidance in docs
"use client"
import * as React from "react"
import { useBollardField } from "@/components/ui/use-bollard-field"
const fieldClass =
"h-10 w-full rounded-md border bg-background px-3 text-sm outline-none transition-colors placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring/40 aria-invalid:border-destructive"
export function Demo() {
const [validationFailure, setValidationFailure] = React.useState<string>()
const email = useBollardField({
initialValue: "priya@acme",
validate: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? undefined : "Enter a complete email address, such as priya@example.com.",
onError: (error) => setValidationFailure(error.code),
})
const submit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
await email.validate()
}
return (
<form noValidate onSubmit={submit} className="w-full max-w-md space-y-3 rounded-lg border bg-card p-4 text-left">
<div className="space-y-1">
<label htmlFor="bollard-email-demo" className="text-sm font-medium">Work email</label>
<input
id="bollard-email-demo"
type="email"
autoComplete="email"
value={email.value}
onChange={(event) => {
setValidationFailure(undefined)
email.setValue(event.target.value)
}}
onBlur={email.onBlur}
{...email.ariaProps}
className={fieldClass}
/>
</div>
<div className="flex items-center justify-between gap-3">
<p id={email.errorId} role={email.invalid ? "alert" : undefined} className="min-h-5 text-xs text-destructive">
{email.error}
</p>
<button
type="submit"
disabled={email.isValidating}
className="h-8 shrink-0 rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground outline-none hover:bg-primary/90 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-wait disabled:opacity-60"
>
{email.isValidating ? "Checking…" : "Continue"}
</button>
</div>
{validationFailure && <p role="status" className="text-xs text-muted-foreground">Check failed ({validationFailure}). The field remains editable; retry validation after recovery.</p>}
<p className="border-t pt-3 text-xs text-muted-foreground">The input stays yours. Bollard supplies field state and accessible error props.</p>
</form>
)
}Was this component page useful?
How do I install useBollardField?
The files land in your project. They're yours to edit.
Copy and paste the following code into
components/ui32 lines// Bollard UI — use-bollard-field · MIT licence · https://bollard-ui.vercel.app/components/use-bollard-field /** A dependency-free error shape for handling failures in Bollard integrations. */ export interface BollardErrorOptions extends ErrorOptions { code?: string retryable?: boolean } export class BollardError extends Error { readonly code: string readonly retryable: boolean constructor(message: string, options: BollardErrorOptions = {}) { super(message, options) this.name = "BollardError" this.code = options.code ?? "UNEXPECTED_ERROR" this.retryable = options.retryable ?? false } } /** Keep a safe, stable field message while retaining the original failure for diagnostics. */ export function toBollardError( cause: unknown, message = "Field validation failed. Try again.", ): BollardError { if (cause instanceof BollardError) return cause return new BollardError(message, { code: "VALIDATION_FAILED", retryable: true, cause, }) }Update the import paths to match your project setup.
It uses the
cn()helper from@/lib/utils, which every shadcn/ui project already has.
What input mistakes does useBollardField catch?
- Validation coupled to a specific input component or UI library
- Async responses overwriting the result for a newer value
- Inline errors not connected to controls with aria-describedby
- Server errors that remain visible after the user edits the field
- Thrown async validator failures silently hidden from application-level logging
How is useBollardField accessible?
- ariaProps connects the control to the error ID and marks invalid state
- Render the error with id={field.errorId} and role=alert or aria-live=polite
- No focus movement or UI is imposed; the consuming form chooses its summary behavior
Only what the source does. Test with your own screen reader and content before shipping.
What are the limitations and server boundaries?
- You provide the validator and render the error message yourself
- This hook manages one field; it does not replace form submission or schema validation
- Validation runs on blur, then again after edits; call validate() for submit-time checks
- Thrown validator failures keep a safe inline message and optionally notify onError with a typed BollardError
What dependencies does useBollardField require?
None beyond React and Tailwind CSS.
useBollardField facts & technical specifications
| Property | Specification |
|---|---|
| Component name | useBollardField |
| Registry identifier | @bollard/use-bollard-field |
| Install command | npx shadcn@latest add @bollard/use-bollard-field |
| License | MIT License (free, commercial-friendly) |
| Price | $0 (100% Free and Open Source) |
| Version | 0.1.0 |
| Requirements | React 19+, Tailwind CSS v4, shadcn CLI |
| SSR support | Fully compatible (SSR & Server Components safe, client-hydrated controls) |
| Dependencies | 0 runtime dependencies |
| Accessibility | WAI-ARIA compliant, keyboard navigability and screen-reader announcements verified |
| Last updated | 2026-10-20 |
| Scope limitation | Client-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization. |
Frequently asked questions about useBollardField
What form validation mistake does useBollardField catch?
useBollardField prevents add touched, async-safe validation state and accessible error props to any React control without changing UI libraries.. Add touched, async-safe validation state and accessible error props to any React control without changing UI libraries. Catches: Validation coupled to a specific input component or UI library, Async responses overwriting the result for a newer value, Inline errors not connected to controls with aria-describedby, Server errors that remain visible after the user edits the field, Thrown async validator failures silently hidden from application-level logging. Limitation: validate use-bollard-field schemas on backend.
How do I install use-bollard-field with shadcn?
Run `npx shadcn@latest add @bollard/use-bollard-field`. Sources added: registry/default/use-bollard-field/error.ts, registry/default/use-bollard-field/use-bollard-field.ts, registry/default/use-bollard-field/validation.ts. Package requirements: zero dependencies for use-bollard-field.
How do I consume the use-bollard-field hook?
Import { useBollardField } from "@/components/ui/use-bollard-field". Returns form bindings and error states. Supports options: default options. Limitation: headless hook requires connecting your own UI components.
What are the limits of use-bollard-field?
You provide the validator and render the error message yourself. This hook manages one field; it does not replace form submission or schema validation. Validation runs on blur, then again after edits; call validate() for submit-time checks. Thrown validator failures keep a safe inline message and optionally notify onError with a typed BollardError Server requirement: backend verification for use-bollard-field.
How does useBollardField meet accessibility guidelines?
ariaProps connects the control to the error ID and marks invalid state. Render the error with id={field.errorId} and role=alert or aria-live=polite. No focus movement or UI is imposed; the consuming form chooses its summary behavior. Minimizes errors: add touched, async-safe validation state and accessible error props to any React control without changing UI libraries..