antlitz
Menu

Checkbox

A binary choice. Renders a native checkbox with appearance: none, so keyboard handling, form submission, and the indeterminate state come from the platform.

import { Checkbox } from "antlitz";

API

PropTypeDefault
indeterminatebooleanfalse
radius"none" | "sm" | "md" | "lg" | "full"none
size"sm" | "md" | "lg"md

indeterminate has no HTML attribute — it is a DOM property — so the component sets it on the element through a ref. The mark is drawn from the element's state rather than the prop, so when a click clears indeterminate the box shows a tick straight away, even before your state catches up.

Usage

export function Basic() {
  return (
    <Field orientation="horizontal" label="Accept the terms">
      <Checkbox defaultChecked />
    </Field>
  );
}

States

export function States() {
  return (
    <>
      <Checkbox aria-label="Unchecked" />
      <Checkbox defaultChecked aria-label="Checked" readOnly />
      <Checkbox indeterminate aria-label="Indeterminate" readOnly />
      <Checkbox disabled aria-label="Disabled" />
      <Checkbox
        disabled
        defaultChecked
        aria-label="Disabled checked"
        readOnly
      />
      <Checkbox aria-invalid aria-label="Invalid" />
      <Checkbox
        aria-invalid
        defaultChecked
        aria-label="Invalid checked"
        readOnly
      />
    </>
  );
}

Invalid fills the box with the danger token rather than only colouring its border: a 1px outline on a 16px box is too little signal to notice.

Sizes

export function Sizes() {
  return (
    <>
      <Checkbox size="sm" defaultChecked aria-label="Small" readOnly />
      <Checkbox size="md" defaultChecked aria-label="Medium" readOnly />
      <Checkbox size="lg" defaultChecked aria-label="Large" readOnly />
    </>
  );
}

The check mark is 65% of the box at every size, so it scales with it.

Radius

export function Radius() {
  return RADII.map((radius) => (
    <Checkbox
      key={radius}
      radius={radius}
      defaultChecked
      readOnly
      aria-label={radius}
    />
  ));
}

Grouping

Notify me about

Select a channel to continue.

export function Group() {
  return (
    <Fieldset
      legend="Notify me about"
      error="Select a channel to continue."
      className="w-full max-w-xs"
    >
      <Field orientation="horizontal" label="Email">
        <Checkbox name="channel" value="email" aria-invalid />
      </Field>
      <Field orientation="horizontal" label="SMS">
        <Checkbox name="channel" value="sms" aria-invalid />
      </Field>
    </Fieldset>
  );
}

Related checkboxes belong in a Fieldset, which gives the group a legend and one shared error message.