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
| Prop | Type | Default | Description |
|---|---|---|---|
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
| Key | Does |
|---|---|
| Tab | Moves between the checkboxes |
| Space | Toggles the focused one |
Accessibility
selectAlladds 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.