Choice Group

updated

Sign 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.

With checkboxes

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 with orientation="horizontal"
  • card: each option is a bordered card
  • list: options share one bordered list
  • table: 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

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.

Data attributes

data-slotAttributesDescription
choice-groupdata-variant, data-orientation, data-colorThe layout when rendered on its own. A checkbox group or radio group keeps its own data-slot and carries the same three attributes.

Changelog

  1. registry 0.22.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

  2. core 0.16.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

  3. registry 0.13.0

    5a478d3 — Checkbox, Radio, Switch, Slider, Progress, Stepper and TabsList take color: primary (the default), neutral, destructive, success, warning, info, or any name you declare on [data-slot][data-color="<name>"], as on Button. The root carries data-color. Whatever they draw straight on the page takes the colour's --tone-text: a checked edge, the radio's dot, the default slider's range and thumb, the progress bar and the tab line. That keeps a bright success, warning or info at 3:1 against the page. Fills with something on them, like the checked box, the switch track and the active step, keep --tone. On the choice controls the unchecked edge stays --input and an invalid control still turns destructive. Keyboard focus rings a control in a colour other than primary in its --tone-text, red once it's invalid. CheckboxGroup and RadioGroup pass their color to every control in them without one, and ChoiceGroup takes color for the selected card's edge, the focused card's ring and the selected row's tint. Switch, Checkbox, Radio and Slider now set data-size, md by default. They need the @kappa-ui/core release that lets tone-control follow data-color.

    Recoloured Switch, Checkbox, Radio or Slider with class="[--tone:…] [--tone-foreground:…]", as the theming page used to suggest? Their edges and marks now read --tone-text, so add [--tone-text:…] to the class, or use color.

  4. registry 0.6.0

    4e35ec3 — Card takes size from xs to xl on one --card-spacing (md is the default and replaces default) and variant: outline (unchanged, the default), solid with a small shadow and no border, soft tinted, subtle tinted with a border. ChoiceGroup is the layout behind CheckboxGroup and RadioGroup's variant and orientation, in its own choice-group item; radio-group depends on it instead of on checkbox.