Choice Group
updatedSign my petition. It's only as complicated as you make it. Layouts for checkbox and radio groups a plain stack, cards, a bordered list or a table, in a column or a row.
A daily summary to your inbox.
Right away, on this device.
Only for security alerts.
Open Props in the corner of the example to try color. The group's color edges the selected card and tints the selected row, primary by default; in any other colour a focused card rings in it too, like the control inside. On a CheckboxGroup or RadioGroup it also colours every control in the group that has no color of its own.
Installation
Usage
You rarely need ChoiceGroup itself: CheckboxGroup and RadioGroup take the same variant and orientation. Reach for it when a set of Fields that aren't checkboxes or radios should look the same.
<script setup lang="ts">
import { Checkbox, CheckboxGroup } from '@/components/ui/checkbox'
import { Field, FieldContent, FieldDescription, FieldLabel } from '@/components/ui/field'
</script>
<template>
<CheckboxGroup variant="card" orientation="horizontal">
<Field orientation="horizontal">
<Checkbox value="email" />
<FieldContent>
<FieldLabel>Email</FieldLabel>
<FieldDescription>A daily summary to your inbox.</FieldDescription>
</FieldContent>
</Field>
</CheckboxGroup>
</template>
default: a simple stack, or a row withorientation="horizontal"card: each option is a bordered cardlist: options share one bordered listtable: label and description get columns of their own
In card, list and table, the whole option is clickable and tints when selected. orientation="horizontal" puts cards in a grid, and list and table rows side by side.
Each option must be a horizontal Field and a direct child of the group. Wrap it in anything else, and the styles won't reach it.
Examples
With radios
One project, community support.
Unlimited projects, email support.
Shared workspaces, priority support.
API Reference
class is also accepted and merged over the layout classes.
ChoiceGroup
| Prop | Default | Type and description |
|---|---|---|
| variant | — | "default" | "card" | "list" | "table" | null
|
| orientation | — | "vertical" | "horizontal" | null
|
| color | "primary" | ChoiceGroupColor | (string & {})Colour role of a selected card's edge and a selected row's tint, and of a focused card's ring in any colour but |
| asChild | — | booleanRender the single child instead of a wrapper, merging the layout's attributes and classes onto it. This is how |
| as | "div" | AsTag | ComponentThe element or component to render. A div by default. |
| Slot | Scope and description |
|---|---|
| default | {}The options, each a horizontal |
Props
- variant
"default" | "card" | "list" | "table" | nulldefaultstacks or wraps the options;card,listandtablemake each whole card or row clickable and tint it once checked.- orientation
"vertical" | "horizontal" | nullhorizontallays the options out in a row: wrapping fordefault, a grid of cards forcard, side-by-side cells forlistandtable.- color
"primary" ChoiceGroupColor | (string & {})Colour role of a selected card's edge and a selected row's tint, and of a focused card's ring in any colour butprimary. Any other name picks up a colour you declare on[data-slot][data-color="<name>"]. It doesn't reach the controls; set their owncolor, or useCheckboxGrouporRadioGroup, which pass theirs down.- asChild
booleanRender the single child instead of a wrapper, merging the layout's attributes and classes onto it. This is howCheckboxGroupandRadioGroupuse it.- as
"div" AsTag | ComponentThe element or component to render. A div by default.
Slots
- default
{}The options, each a horizontalFieldwith its control and label.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| choice-group | data-variant, data-orientation, data-color | The layout when rendered on its own. A checkbox group or radio group keeps its own data-slot and carries the same three attributes. |