Dashral Pro is hereSee pricing

Dashral

Checkbox GroupNew

Several checkboxes under one label, to pick any number of options.

$ pnpm dlx shadcn@latest add @dashral/checkbox-group

To maya@driftbox.example

On your phone and desktop

Only for security alerts

Connect a workspace first

We'll only send what you pick.

Installation

$ pnpm dlx shadcn@latest add @dashral/checkbox-group

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/checkbox-group.json

Usage

example.tsx
import { CheckboxGroup } from "@/components/dashral/checkbox-group"

<CheckboxGroup
  label="Notify me by"
  options={["Email", "Push", "SMS"]}
  value={channels}
  onValueChange={setChannels}
/>

Using the npm package? Import from @dashral/ui/components/checkbox-group instead, here and in the examples; the rest is the same.

Examples

Cards with a limit

variant="cards" with icons; max disables the rest once it's reached.

Pick up to two.

Select all

selectAll ticks or clears them all, half-ticked while some are; in two columns.

API reference

CheckboxGroup

PropTypeDefault
labelReactNode

Shown above, linked to the control.

—
descriptionReactNode

A hint under the control.

—
errorboolean | ReactNode

true shows the error style; a message also shows under the control.

—
labelActionReactNode

At the end of the label's row, e.g. a “Forgot password?” link or the current value.

—
withAsteriskboolean

Marks the label with an asterisk, e.g. alongside required.

false
options(string | { value, label?, description?, icon?, disabled? })[]

The checkboxes. Required.

—
value / defaultValuestring[]

The ticked values, controlled or initial; always in the options' order.

[]
onValueChange(value: string[]) => void

Called with the new value.

—
variant"default" | "cards"

Checkboxes with labels, or bordered cards you click anywhere on.

"default"
selectAllboolean | ReactNode

A checkbox above the rest that ticks or clears them all, half-ticked while some are. true for "Select all".

—
maxnumber

At most this many; the rest are disabled once it's reached.

—
color"primary" | "neutral" | "info" | "success" | "warning" | "destructive" | "highlight"

A ticked checkbox (and card).

"primary"
namestring

The form field's name; each ticked value is sent under it.

—
disabled / requiredboolean

As on other controls.

—
classNames{ root, label, description, error, group, item, checkbox }

Classes for each part.

—
classNamestring

The group's classes, e.g. columns: "sm:grid-cols-2".

—

Keyboard

KeysAction
TabMove between checkboxes
SpaceTick or clear the focused one

Accessibility

  • With label, description or error, the id, aria-describedby and aria-invalid are wired up for you.
  • role="group" named by the label, so each checkbox is read with it.
  • "Select all" is a real checkbox with the mixed state while some are ticked.