Tuimorphic

Checkbox

Terminal-style checkbox with [X] indicator for boolean selections.

Import

import { Checkbox } from 'tuimorphic';

Basic Usage

<Checkbox label="Accept terms and conditions" />

Props

PropTypeDefaultDescription
checkedbooleanWhether the checkbox is checked (controlled)
defaultCheckedbooleanfalseDefault checked state (uncontrolled)
onCheckedChange(checked: boolean) => voidCallback when checked state changes
labelstringLabel text displayed next to checkbox
disabledbooleanfalseWhether the checkbox is disabled
namestringName attribute for forms
valuestringValue attribute for forms
classNamestringAdditional CSS class names
refReact.Ref<HTMLButtonElement>Forwarded ref to the button element

With Label

<Checkbox label="Accept terms and conditions" />

Checkbox Group

<div className="space-y-2">
  <Checkbox label="Option A" />
  <Checkbox label="Option B" />
  <Checkbox label="Option C" />
</div>

Disabled States

<Checkbox label="Disabled unchecked" disabled />
<Checkbox label="Disabled checked" disabled checked />

Controlled Checkbox

State: Unchecked
const [checked, setChecked] = useState(false);
 
<Checkbox
  label="I agree to the terms"
  checked={checked}
  onCheckedChange={setChecked}
/>

Multiple Selections Example

For multiple selections, manage state manually:

const [selected, setSelected] = useState<string[]>(['notifications']);
 
const toggleOption = (option: string) => {
  setSelected((prev) =>
    prev.includes(option)
      ? prev.filter((o) => o !== option)
      : [...prev, option]
  );
};
 
<fieldset>
  <legend>Notification Preferences</legend>
  <Checkbox
    label="Email notifications"
    checked={selected.includes('email')}
    onCheckedChange={() => toggleOption('email')}
  />
  <Checkbox
    label="Push notifications"
    checked={selected.includes('notifications')}
    onCheckedChange={() => toggleOption('notifications')}
  />
  <Checkbox
    label="SMS notifications"
    checked={selected.includes('sms')}
    onCheckedChange={() => toggleOption('sms')}
  />
</fieldset>

Visual Design

The checkbox uses a terminal-style indicator:

  • Unchecked: [ ]
  • Checked: [X]

Keyboard Navigation

KeyAction
SpaceToggle checked state
EnterToggle checked state
TabMove focus to next element

Accessibility

  • Built on Base UI's accessible checkbox primitive
  • Proper ARIA attributes for screen readers
  • Keyboard accessible
  • Label properly associated with checkbox

Styling

VariableDescription
--theme-borderCheckbox border color
--theme-textIndicator and label color
--theme-focused-borderBorder color when focused
  • Radio - For single selection from multiple options
  • Toggle - For on/off switches

On this page