Checkbox

A native checkbox with an 18px box, for independent yes/no choices and for picking several items from a list. It submits with forms like any <input type="checkbox">.

StableSource

Import

tsx
import { Checkbox } from "@merid/react";

Examples

With description

description renders a second line under the label and links it with aria-describedby.

Includes invoices, receipts and plan changes.

Controlled

Uncontrolled checkboxes use defaultChecked. To control one, pass checked and read event.target.checked in onChange.

checked: false

Indeterminate

indeterminate shows the mixed “–” state, typically on a parent that is partly selected. It sets the DOM indeterminate property, which assistive tech reports as aria-checked="mixed".

Disabled and invalid

Without a visible label

Omit children and pass aria-label, for example in a table's selection column.

API reference

The ref and native input attributes (checked, defaultChecked, onChange, name, value, …) go to the <input>. className and style go to the outer wrapper.

PropTypeDefaultDescription
childrenReactNode–Visible label next to the box. Omit and pass aria-label for a bare checkbox. Inside a `Field`, the Field label names the checkbox and children become its description.
descriptionReactNode–Secondary line under the label, linked via aria-describedby.
indeterminatebooleanfalseShows the mixed state and sets the DOM indeterminate property.
invalidboolean–Forces the invalid style (`data-invalid`) and `aria-invalid`.
checkedboolean–Checked state (controlled).
defaultCheckedboolean–Initial checked state (uncontrolled).
disabledboolean–Disables the input and dims the label.

Styling

HookValues
.mrd-checkboxOuter wrapper; receives className and style
.mrd-checkbox__controlBox container
.mrd-checkbox__inputThe native <input>
.mrd-checkbox__iconCheck / dash SVG
.mrd-checkbox__text, __label, __descriptionLabel column
data-disabled, data-invalidOn the wrapper
data-invalidOn the input when invalid; draws the danger ring
data-indeterminateOn the input while mixed

The invalid ring is driven by data-invalid on the input; aria-invalid carries the semantics. Checkbox has no component variables; it uses --mrd-accent, --mrd-line-strong and --mrd-danger.

Accessibility

  • A native checkbox: checked state, disabled state and form submission come from the platform.
  • The label is a real <label htmlFor>, so clicking the text toggles the box.
  • Inside a Field, the Field label names the checkbox (aria-labelledby). Children still render as a clickable label but are linked as its description (aria-describedby), so the control is never double-labelled.
  • Group related checkboxes in a fieldset with a legend, or a container with role="group" and aria-labelledby.
KeyAction
TabMoves focus to the checkbox.
SpaceToggles the checkbox.

Guidelines

Do

Write labels as positive statements that are true when checked: “Email me about updates”.

Avoid

Use negative labels like “Don’t send me emails” — checked-means-no is easy to misread.

Do

Use a checkbox for a choice that is saved when the form is submitted.

Avoid

Use it for a setting that takes effect immediately — that is a Switch.

  • Switch — immediate on/off settings.
  • Radio — one choice from a set.
  • Table — row selection with checkboxes.