Skip to content
Porcelana

Checkbox

Checkbox with an optional label row and an indeterminate (mixed) state.

Example

Example.tsx
import { useState } from "react";
import { Checkbox } from "@porcelana/ui";

export default function Example() {
  const [days, setDays] = useState({ mon: true, sat: false });
  const all = days.mon && days.sat ? true : days.mon || days.sat ? "indeterminate" : false;
  return (
    <div style={{ display: "grid", gap: 4 }}>
      <Checkbox
        label="Every day"
        checked={all}
        onCheckedChange={(v) => setDays({ mon: v === true, sat: v === true })}
      />
      <Checkbox label="Monday" checked={days.mon} onCheckedChange={(v) => setDays({ ...days, mon: v === true })} />
      <Checkbox label="Saturday" checked={days.sat} onCheckedChange={(v) => setDays({ ...days, sat: v === true })} />
    </div>
  );
}

Import

Import
import { Checkbox } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

Checkbox

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
checkedCheckedState–Controlled checked state. Use with onCheckedChange.
defaultCheckedCheckedState–Initial checked state when uncontrolled.
disabledboolean–Prevents interaction and dims the control.
idstring–Element id. Generated automatically when omitted.
labelReactNode–Visible label. The whole row (box + label) is the 44px touch target.
onCheckedChange((checked: CheckedState) => void)–Called with the new checked state.
requiredboolean–Marks the control as required in forms.
type"button" | "submit" | "reset"–Button type (defaults to "button").

Accessibility

  • Space toggles; checked="indeterminate" is announced as mixed.
  • With label, clicking the text toggles the box.

Mobile

  • The whole label row is a 44px touch target; the box itself has an invisible 44px hit area.