Selected: react
parentdisabledimport { useState } from "react"
import { Checkbox } from "@/components/ui/checkbox"
import { CheckboxGroup } from "@/components/ui/checkbox-group"
const frameworks = [
{ value: "react", label: "React" },
{ value: "vue", label: "Vue" },
{ value: "angular", label: "Angular" },
]
export function FrameworkPicker() {
const [selected, setSelected] = useState<string[]>(["react"])
return (
<div className="space-y-3">
<div id="frameworks-label" className="text-sm font-medium">
Select frameworks you know
</div>
<CheckboxGroup
aria-labelledby="frameworks-label"
value={selected}
onValueChange={setSelected}
>
{frameworks.map((f) => (
<div key={f.value} className="flex items-center space-x-2">
<Checkbox id={f.value} name="frameworks" value={f.value} />
<label htmlFor={f.value} className="text-sm">{f.label}</label>
</div>
))}
</CheckboxGroup>
<p className="text-sm text-muted-foreground">
Selected: {selected.length > 0 ? selected.join(", ") : "None"}
</p>
</div>
)
}Usage
import { Checkbox } from "@/components/ui/checkbox"
import { CheckboxGroup } from "@/components/ui/checkbox-group"
const toppings = [
{ value: "cheese", label: "Cheese" },
{ value: "olives", label: "Olives" },
{ value: "peppers", label: "Peppers" },
]
export function ToppingsPicker() {
return (
<div>
<p id="toppings-label" className="text-sm font-medium">Toppings</p>
<CheckboxGroup aria-labelledby="toppings-label" defaultValue={["cheese"]}>
{toppings.map((t) => (
<div key={t.value} className="flex items-center gap-2">
<Checkbox id={t.value} value={t.value} />
<label htmlFor={t.value} className="text-sm">{t.label}</label>
</div>
))}
</CheckboxGroup>
</div>
)
}Examples
Selected: react
import { CheckboxGroup } from '@/components/ui/checkbox-group';
import { Checkbox } from '@/components/ui/checkbox';
import { useState } from 'react';
export function Example() {
const [selected, setSelected] = useState<string[]>(["react"]);
return (
<div className="space-y-3">
<label className="text-sm font-medium text-foreground">
Select frameworks you know
</label>
<CheckboxGroup value={selected} onValueChange={setSelected}>
<div className="flex items-center space-x-2">
<Checkbox id="react" name="frameworks" value="react" />
<label htmlFor="react" className="text-sm text-foreground">React</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="vue" name="frameworks" value="vue" />
<label htmlFor="vue" className="text-sm text-foreground">Vue</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="angular" name="frameworks" value="angular" />
<label htmlFor="angular" className="text-sm text-foreground">Angular</label>
</div>
</CheckboxGroup>
<p className="text-sm text-muted-foreground">
Selected: {selected.length > 0 ? selected.join(", ") : "None"}
</p>
</div>
);
}import { CheckboxGroup } from '@/components/ui/checkbox-group';
import { Checkbox } from '@/components/ui/checkbox';
export function Example() {
return (
<div className="space-y-3">
<label className="text-sm font-medium text-foreground">
Select your interests
</label>
<CheckboxGroup defaultValue={["design"]}>
<div className="flex items-center space-x-2">
<Checkbox id="design" name="interests" value="design" />
<label htmlFor="design" className="text-sm text-foreground">Design</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="development" name="interests" value="development" />
<label htmlFor="development" className="text-sm text-foreground">Development</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="marketing" name="interests" value="marketing" />
<label htmlFor="marketing" className="text-sm text-foreground">Marketing</label>
</div>
</CheckboxGroup>
</div>
);
}import { CheckboxGroup } from '@/components/ui/checkbox-group';
import { Checkbox } from '@/components/ui/checkbox';
export function Example() {
return (
<div className="space-y-3">
<label className="text-sm font-medium text-foreground">
Notification preferences
</label>
<CheckboxGroup defaultValue={["email"]} className="flex flex-row gap-6">
<div className="flex items-center space-x-2">
<Checkbox id="email-notif" name="notifications" value="email" />
<label htmlFor="email-notif" className="text-sm text-foreground">Email</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="sms-notif" name="notifications" value="sms" />
<label htmlFor="sms-notif" className="text-sm text-foreground">SMS</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="push-notif" name="notifications" value="push" />
<label htmlFor="push-notif" className="text-sm text-foreground">Push</label>
</div>
</CheckboxGroup>
</div>
);
}import { CheckboxGroup } from '@/components/ui/checkbox-group';
import { Checkbox } from '@/components/ui/checkbox';
export function Example() {
return (
<div className="space-y-3">
<label className="text-sm font-medium text-muted-foreground">
Plan features (upgrade to enable)
</label>
<CheckboxGroup disabled defaultValue={["basic"]}>
<div className="flex items-center space-x-2">
<Checkbox id="basic" name="features" value="basic" />
<label htmlFor="basic" className="text-sm text-muted-foreground">Basic features</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox id="advanced" name="features" value="advanced" />
<label htmlFor="advanced" className="text-sm text-muted-foreground">Advanced features</label>
</div>
</CheckboxGroup>
</div>
);
}Notes
Checkbox values
A Checkbox joins the group through its value. Without one it is not in the group's list or the agent's items.
Parent checkbox
Pass allValues and add a <Checkbox parent />. It ticks or clears every child and shows mixed when some are ticked. Disabled children are left alone.
API
details.cancel() refuses the change.parent checkbox.Agent
Inside an AgentProvider, it appears in agent.snapshot() as checkbox-group.
Reads
labelThe group's aria-label or aria-labelledby. Unnamed groups go by checkbox-group.
valueThe labels of the ticked checkboxes.
itemsEvery checkbox's label, in order.
multipleAlways true.
disabledTrue when the whole group is blocked.
Actions
setValue(["React", "Vue"])Ticks exactly these, by label then by value. A miss lists the options. Disabled checkboxes keep their state.
Each checkbox is also listed and takes toggle and setChecked, which run through the group's onValueChange like setValue. isAgentChange(details) is true there; details.cancel() refuses and tells the agent. Naming a disabled checkbox fails; a disabled group refuses on its own.
await agent.act({
steps: [{ ref: "checkbox-group", action: "setValue", args: [["React", "Vue"]] }],
})Accessibility
- Renders role="group". Name it with aria-labelledby or aria-label; the agent reads the same name.
- Each checkbox needs its own label, also its name in the agent's items.
- A parent checkbox reports mixed while some children are ticked.