Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Core

CheckboxGroup

A set of checkboxes: pick any number. ref points at the first checkbox that can take focus ("Select all" when shown).

import { CheckboxGroup } from "@stylhero/ui";

Example

Code
import { CheckboxGroup } from "@stylhero/ui";

function CheckboxGroupExample() {
  return (
    <CheckboxGroup legend="Toppings" selectAll="All toppings" defaultValue={["cheese"]}
      options={["cheese", "mushrooms", "peppers", "olives"]} />
  );
}

Props

PropTypeDefaultDescription
legend required ReactNode - The group's question, e.g. "Notify me by".
options required Array<ChoiceOption | string> -
defaultValue string[] []
error ReactNode -
hint ReactNode -
name string - Submits each checked value under this name in native forms.
onValueChange (value: string[]) => void -
row boolean - Lay the options out side by side.
selectAll ReactNode - Adds a "Select all" checkbox on top (with the mixed state).
value string[] -

Also takes every <fieldset> attribute (id, style, data-*, aria-*, event handlers…), passed to that element. Takes a ref.

Types

type ChoiceOption = { value: string; label: ReactNode; hint?: ReactNode; disabled?: boolean };

Keyboard

KeyDoes
TabMoves between the checkboxes
SpaceToggles the focused one

Accessibility

  • selectAll adds a checkbox that's announced as "mixed" when some options are checked.

Generated from src/components/FieldSet.tsx. Something wrong or missing? Open an issue.