Loading component…
Loading component…
The frame around any control
To reuse this local React demo, copy all files from the Code tab into the same folder, then import FormField from ./form-field.
import { useState } from "react";
import { FormField } from "@/components/ui/form-field";
export function AgentForm() {
const [name, setName] = useState("");
const [budget, setBudget] = useState("40");
const over = Number(budget) > 100;
return (
<form className="grid gap-4">
<FormField label="Agent name" required counter={`${name.length}/40`}>
<input value={name} maxLength={40} onChange={(e) => setName(e.target.value)} />
</FormField>
<FormField
label="Budget per run"
hint="In US dollars – the run stops once it's spent."
error={over ? "Your plan allows up to $100 per run." : undefined}
>
<input inputMode="decimal" value={budget} onChange={(e) => setBudget(e.target.value)} />
</FormField>
{/* Controls that need the ids somewhere else get them as a function */}
<FormField label="Reasoning" hint="How long the agent may think.">
{(field) => <EffortPicker {...field} aria-labelledby={field.labelId} />}
</FormField>
</form>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | Shown above the control; a <label> tied to it, so a click focuses it | |
| hint | ReactNode | A quiet line under the control – the error takes its place while there is one | |
| error | ReactNode | Shows the message where the hint was and sets aria-invalid on the control; true marks it invalid without a line | |
| required | boolean | false | A quiet * after the label and aria-required on the control; native inputs, selects and textareas also get required |
| optional | boolean | false | "Optional" next to the label – for forms where most fields are required |
| counter | ReactNode | At the end of the line under the control, e.g. "12/40" – linked with aria-describedby | |
| disabled | boolean | false | Dims the whole field and passes disabled to the control |
| htmlFor | string | The control's id – by default it keeps its own id or gets one made up | |
| children | ReactElement \| (field) => ReactNode | One element, which gets id, aria-describedby, aria-invalid and aria-required – or a function that receives them (plus labelId) to spread where they belong | |
| ...div props | ComponentProps<"div"> | className, style, ref and the rest go on the wrapper |
Fills its container; long labels and messages wrap, even unbroken words, and never push it wider
The count keeps its place at the end of the line while the hint wraps beside it
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.