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 />
A yes or no is a 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>
A checkbox with the words beside it, not in it, names nothing: clicking the words does nothing.

Row

Do
import { Checkbox } from "@hackcove/ui";

<Checkbox size="sm" aria-label="Select row" />
In a table cell there is no room for words: leave the label out, use size="sm" and name the box with aria-label.

Usage

  • Give a Checkbox a label; the whole label is the click target.
  • In a table cell leave the label out, use size="sm" and name the box with aria-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 Checkbox in a Field; it is its own label.
  • Choosing one of several is a Select or a SegmentedControl, 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-label is 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