Examples
CheckboxGroup
A set of checkboxes for picking any number of options. Give it options and it draws them; value is the array of checked values, in the options' order. For one choice, use a RadioGroup.
import { CheckboxGroup } from 'patine-ui';
Loading…
<Box border radius="lg" padding="lg" gap="sm" style={{ maxWidth: 380 }}> <Text weight="semibold">Email me about</Text> <CheckboxGroup options={EMAILS} value={emails} onValueChange={setEmails} selectAllLabel="All notifications" aria-label="Email notifications" /> </Box>
Try the props
selectAllLabelorientationcontrolPositiondesign<CheckboxGroup
options={toppings}
value={toppings}
onValueChange={setToppings}
/>
Example: export your data
An account's privacy page: pick what to include in the export. Select all checks every allowed item, the size adds up as you go, and Export stays off until something is picked.
Loading…
<Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 420 }}> <Text weight="semibold">Download your data</Text> <CheckboxGroup options={DATA} value={picked} onValueChange={setPicked} selectAllLabel="Everything" aria-label="Data to export" /> <Button disabled={!picked.length}>{picked.length ? `Export · ${size}` : 'Pick something to export'}</Button> <Text size="sm" color="textSecondary">We email you a link when the archive is ready. It works for 7 days.</Text> </Box>
Select all
selectAllLabel adds a parent box above the options. It's checked when every enabled option is, shows a dash (mixed) when some are, and checks or clears them all. Disabled options keep their state.
Accessibility
- The options are a
group; name it witharia-label. Each is acheckboxwith itscheckedanddisabledstate, named by its label and described by its description. The select-all box reads as mixed when some are checked. - Every row is a 44pt touch target. On the web, Tab moves between boxes and Space toggles one.
Props
Also takes View props.
| Prop | Type | Default | Description |
|---|---|---|---|
options | { value, label?, description?, disabled? }[] | — | The choices. |
value | string[] | — | The checked values, controlled. |
defaultValue | string[] | [] | The checked values when uncontrolled. |
onValueChange | (value: string[]) => void | — | Called when the user checks or unchecks one. |
selectAllLabel | ReactNode | — | Adds a parent box that checks or clears them all. |
orientation | 'vertical' | 'horizontal' | 'vertical' | A column, or rows that wrap. |
controlPosition | 'start' | 'end' | 'start' | Which side of its label each box sits on. |
disabled | boolean | false | Disables every option. |
theme, design | As every component. |