Skip to content

Checkbox Group

A set of checkable buttons where multiple options can be selected at a time.

To display a checkbox group, list two or more CheckboxGroupItem components within CheckboxGroup.

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup defaultValue={["author"]} label="Customization">
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" />
</CheckboxGroup>
);

Display checkboxes horizontally by passing orientation="horizontal".

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup
defaultValue={["reduce-motion"]}
orientation="horizontal"
label="Accessibility"
>
<CheckboxGroupItem value="high-contrast" label="High Contrast" />
<CheckboxGroupItem value="reduce-motion" label="Reduce Motion" />
</CheckboxGroup>
);

The entire group can be disabled by using the disabled prop.

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup
defaultValue={["author", "steps"]}
disabled
label="Customization"
>
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" />
</CheckboxGroup>
);

The disabled prop can also be used to disable a specific CheckboxGroupItem.

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup defaultValue={["author"]} label="Customization">
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" disabled />
</CheckboxGroup>
);

Unlike RadioGroup, CheckboxGroup allows multiple items to be selected simultaneously.

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup defaultValue={["author", "steps"]} label="Customization">
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" />
</CheckboxGroup>
);

Display links to each section

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup defaultValue={["author", "steps"]} label="Customization">
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem
value="toc"
label="Show table of contents"
helpText="Display links to each section"
/>
</CheckboxGroup>
);

By default, CheckboxGroup is uncontrolled, meaning it manages its own state locally. To make it controlled, set value and onValueChange.

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
import { useState } from "react";
export default () => {
const [checkboxValues, setCheckboxValues] = useState(["toc"]);
return (
<CheckboxGroup
value={checkboxValues}
onValueChange={(values) => setCheckboxValues(values)}
label="Customization"
>
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" />
</CheckboxGroup>
);
};

A smaller version of the checkbox group may be used by passing size="sm".

import { CheckboxGroup, CheckboxGroupItem } from "stylus-ui/CheckboxGroup";
export default () => (
<CheckboxGroup defaultValue={["time"]} size="sm" label="Customization">
<CheckboxGroupItem value="author" label="Show author" />
<CheckboxGroupItem value="steps" label="Show step count" />
<CheckboxGroupItem value="time" label="Show creation time" />
<CheckboxGroupItem value="toc" label="Show table of contents" />
</CheckboxGroup>
);
KeyDescription
TabMove focus into and out of the checkbox group
Navigate between options (vertical layout)
Navigate between options (horizontal layout)
SpaceToggle the focused option
HomeJump to first option
EndJump to last option

A set of checkable buttons where multiple options can be selected at a time.

defaultValue

string & CheckboxGroupValue | number & CheckboxGroupValue | readonly string[] & CheckboxGroupValue

Initial selected values when uncontrolled.


disabled

boolean = false

Disable all checkboxes in the group.


label

string

Label shown above the group.


loop

boolean = true

Whether keyboard focus loops within the group.


name

string

Name for the group (used for form submission).


onValueChange

(value: CheckboxGroupValue) => void

Called when the selection changes.


orientation

"horizontal" | "vertical" = "vertical"

Layout direction: vertical (stacked) or horizontal (row).


required

boolean = false

Require at least one selection.


size

"default" | "sm" = "default"

Size of each checkbox: default or sm.


theme

"light" | "dark" = "light"

Visual theme for the group and items.


value

CheckboxGroupValue

Controlled selected values (array of option values).


An individual checkbox item within a CheckboxGroup. Must be rendered inside CheckboxGroup.

value

Required
string

Value for this option when selected (included in group value array).


align

"left" | "right" = "left"

Position of the label relative to the box: left or right.


asChild

boolean

checked

false | true | "indeterminate"

children

ReactNode

Additional content below the label.


defaultChecked

false | true | "indeterminate"

helpText

string

Helper text shown below the checkbox.


label

string

Label shown beside the checkbox.


onCheckedChange

(checked: CheckedState) => void

required

boolean

size

"default" | "sm" = "default"

Override group size for this item.


theme

"light" | "dark" = "light"

Override group theme for this item.