Forms
Checkbox group
Several checkboxes with one value, the list of the checked ones, and a box that checks them all.
Forms
Several checkboxes with one value, the list of the checked ones, and a box that checks them all.
Change the props on the right. The group and its code follow.
import { Checkbox } from 'omuk-ui/checkbox';
import { CheckboxGroup } from 'omuk-ui/checkbox-group';
import { Label } from 'omuk-ui/label';
<CheckboxGroup
aria-label="Email me about"
defaultValue={['mentions']}
allValues={['comments', 'mentions', 'deploys']}
>
<Checkbox id="all" parent />
<Label htmlFor="all">Everything</Label>
<Checkbox id="comments" value="comments" />
<Label htmlFor="comments">comments</Label>
<Checkbox id="mentions" value="mentions" />
<Label htmlFor="mentions">mentions</Label>
<Checkbox id="deploys" value="deploys" />
<Label htmlFor="deploys">deploys</Label>
</CheckboxGroup>Each Checkbox in the group has a value; the group's value is the list of the checked ones. Name the group with aria-labelledby or aria-label.
Email me about
Value: ["mentions"]
Give the group allValues and add a Checkbox with parent. It is checked when every value is, shows a dash when only some are, and a click checks them all, or clears them.
CheckboxGroup takes every prop of a <div> as well. A Checkbox in it takes value and parent.