Field
Label, control, description and error as one unit. Controls inside (Input, Textarea, Select, Checkbox, Switch, RadioGroup) get id, aria-describedby, aria-invalid and required automatically; errors spring in and are announced.
"use client";import { useState } from "react";import { Button } from "@/components/ui/button";import { Field } from "@/components/ui/field";import { Input } from "@/components/ui/input";export function SignupForm() { const [error, setError] = useState<string>(); return ( <form noValidate onSubmit={(e) => { e.preventDefault(); const email = String(new FormData(e.currentTarget).get("email")); setError( email.includes("@") ? undefined : "Enter a valid email address.", ); }} > <Field label="Email" description="We never share it." error={error} required > <Input name="email" type="email" /> </Field> <Button type="submit">Create account</Button> </form> );}<Field>
Label, control, description and error as one unit, with ids and ARIA wired automatically.
children*ReactNodeOne form control; it picks up id, aria and state from the Field.
descriptionReactNodeHint under the control.
disableddefaultfalsebooleanDims the label and disables the control.
errorReactNodeShown under the control and marks it aria-invalid. Springs in and out.
idstringUse when the control renders its own id (it must match).
labelReactNodeLabel wired to the control's id.
orientationdefault"vertical""vertical" | "horizontal""horizontal": control first, label beside it (Checkbox, Switch).
requireddefaultfalsebooleanMarks the label and makes the control required.
| Prop | Type | Default |
|---|---|---|
children*One form control; it picks up id, aria and state from the Field. | ReactNode | — |
descriptionHint under the control. | ReactNode | — |
disabledDims the label and disables the control. | boolean | false |
errorShown under the control and marks it aria-invalid. Springs in and out. | ReactNode | — |
idUse when the control renders its own id (it must match). | string | — |
labelLabel wired to the control's id. | ReactNode | — |
orientation"horizontal": control first, label beside it (Checkbox, Switch). | "vertical" | "horizontal" | "vertical" |
requiredMarks the label and makes the control required. | boolean | false |
useFieldControl()
For controls: fills id, aria-describedby, aria-invalid, required and disabled from the enclosing <Field>. Explicit props win. Outside a Field it returns the props unchanged.
useFieldControl(props: Props) => Props
* required. Every component also takes className.