Skip to main content

Checkbox

Live preview

Result
Loading...
Live Editor
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
  <Checkbox label="Remember me" defaultChecked />
  <Checkbox label="I agree to the terms" />
  <Checkbox label="Mixed selection" indeterminate />
  <Checkbox label="Disabled" disabled />
</div>

Renders a native <input type="checkbox"> wrapped in a styled label. Supports the three standard states: unchecked, checked, and indeterminate (mixed-selection state used by "select all" toggles).

Import

import { Checkbox } from 'chromium-ui-react';

Props

PropTypeDefaultDescription
labelReactNodeText or node placed to the right of the box
indeterminatebooleanfalseRenders the mixed-state dash; overrides visual checked
checkedbooleanControlled mode
defaultCheckedbooleanUncontrolled mode
onChange(e: ChangeEvent) => voidStandard change handler
disabledbooleanfalseDisables the control
name, value, id, ...All native <input> attributes forwarded

Ref forwards to the underlying <input>.

Basic usage

<Checkbox label="Remember me" defaultChecked />
<Checkbox label="I agree to the terms" />
<Checkbox label="Disabled" disabled />

Controlled

const [checked, setChecked] = useState(false);

<Checkbox
label="Enable notifications"
checked={checked}
onChange={(e) => setChecked(e.currentTarget.checked)}
/>

Indeterminate ("Select all")

function SelectAll({ items, selected, onToggleAll }) {
const allSelected = selected.length === items.length;
const someSelected = selected.length > 0 && !allSelected;

return (
<Checkbox
label={`${selected.length} selected`}
checked={allSelected}
indeterminate={someSelected}
onChange={(e) => onToggleAll(e.currentTarget.checked)}
/>
);
}

indeterminate is not part of the HTML attribute set — under the hood, the component applies it imperatively via inputRef.current.indeterminate = true in a useEffect.

Without a label

Omit the label prop if you're placing the checkbox in a table cell or composing a custom layout. Provide an external aria-labelledby or aria-label in that case.

<Checkbox aria-label="Select row 3" />

Accessibility

  • The label and box share one <label>, so clicking the label text toggles the box natively.
  • Use Toggle instead when the control represents an on/off setting rather than a selection.