Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Form Field

Pure structure, no state machine. It stacks a label, an optional description, the control you pass as children, and an optional error message. The component derives the ids that tie them together for screen reader wiring.

React FormFieldlive
import { FormField, Input } from "@/components/ui/form-field";
<FormField id="full-name" label="Full name" description="As it appears on your ID.">
<Input id="full-name" aria-describedby="full-name-desc" placeholder="Full name" />
</FormField>
<FormField id="email" label="Email" error="Enter a valid email address.">
<Input id="email" invalid aria-describedby="email-error" />
</FormField>
Terminal window
npx @glaceon/cli add form-field --framework react # or svelte, solid

The wrapper cannot reach into your control, so three ids have to line up. The component owns two of them and derives them from the id prop you pass.

Element Attribute Value
label for the id you pass
description id ${id}-desc
error id ${id}-error
error role alert, announced when it appears

Your control must use the same id, and point its aria-describedby at -desc and -error when those render. This is the one thing the component cannot do for you.

Prop Type Default Description
id string required Base id, shared with the control.
label string undefined Renders a <label for={id}>.
description string undefined Helper text, id ${id}-desc.
error string undefined Error text in --danger, id ${id}-error, role="alert".
class / className string undefined Extra classes, appended last.

The error is a live region, so a message that appears after a failed submit is announced without moving focus. Each part renders only when it has content, which keeps the described-by targets honest: aria-describedby never points at an element that is not there.