"use client";
import { Checkbox, Stack, Text, useCheckboxGroup } from "@vortexlabs/vortex";
const Selection = () => {
const group = useCheckboxGroup();
if (!group) return null;
return <Text>Selected: {group.value?.join(", ") || "None"}</Text>;
};
export const UseCheckboxGroupExample = () => (
<Checkbox.Group name="checkbox-contact-method" defaultValue={["email"]}>
<Checkbox.GroupLabel>Contact method</Checkbox.GroupLabel>
<Stack gap={3}>
<Checkbox.Item value="email" label="Email" />
<Checkbox.Item value="sms" label="SMS" />
<Selection />
</Stack>
</Checkbox.Group>
);Features
- Reads the closest group's selection and shared state.
- Updates when the group value changes.
- Returns
nulloutside the group.
The hook takes no arguments. Call it in a descendant of Checkbox.Group; a group returned by the same component does not provide context to that call.
Use Checkbox.Item for selectable controls. It handles input events and accessibility. See Checkbox for controlled state and group setup.