Checkbox
A yes or no, with its label.
Overview
An on/off option the person ticks: a setting, a filter, a row to select.
Label
Do
import { Checkbox } from "@hackcove/ui";
<Checkbox label="Email me when a shop I follow posts" defaultChecked />
Checkbox with its label: the whole label is the click target.Don't
Email me when a shop I follow posts
import { Body, Checkbox, Cluster } from "@hackcove/ui";
<Cluster gap="sm">
<Checkbox />
<Body>Email me when a shop I follow posts</Body>
</Cluster>Row
Do
import { Checkbox } from "@hackcove/ui";
<Checkbox size="sm" aria-label="Select row" />
label out, use size="sm" and name the box with aria-label.Usage
- Give a
Checkboxalabel; the whole label is the click target. - In a table cell leave the
labelout, usesize="sm"and name the box witharia-label. align="start"puts the box on the first line of a label that wraps onto several; the default centres it.- Do not wrap a
Checkboxin aField; it is its own label. - Choosing one of several is a
Selector aSegmentedControl, not a row of checkboxes.
Accessibility
- A native
<input type="checkbox">inside a<label>, so clicking the text toggles it and the label is its name. - A bare box has no name of its own:
aria-labelis required. - The focus ring comes from the component.
API
Checkbox
A native checkbox with its label. Every prop but the label goes on the input. size="sm" is text-xs and a smaller box, for a dense row. Leave label out for a bare box in a table cell, and name it with aria-label. align="start" puts the box on the label's first line, for a label that wraps onto several; the default centres it on the whole label. The box keeps its size either way.
align- Type
"center" | "start"- Default
center
label- Type
ReactNode
size- Type
"sm" | "md"- Default
md