Components

Checkbox

Binary selection control with checked, unchecked, and indeterminate states for use in forms.

Category: Form / Standalone

Dependency: @base-ui-components/react

Preview

Loading preview...
import { Checkbox, Label } from "@hareru/ui"

<div style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}>
  <Checkbox id="terms" />
  <Label htmlFor="terms">Accept terms and conditions</Label>
</div>

Import

import { Checkbox, CheckboxIndicator } from "@hareru/ui"

Exports

NameTypeDescription
CheckboxComponentRoot checkbox control (renders CheckboxIndicator automatically)
CheckboxIndicatorComponentInternal visual indicator (checkmark / dash)
CheckboxPropsTypeProps interface for Checkbox
CheckboxIndicatorPropsTypeProps interface for CheckboxIndicator

Types

export interface CheckboxProps
  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange"> {
  checked?: boolean
  defaultChecked?: boolean
  onCheckedChange?: (checked: boolean) => void
  indeterminate?: boolean
  disabled?: boolean
  name?: string
  value?: string
  required?: boolean
}

Key Props

PropTypeDefaultDescription
checkedbooleanControlled checked state
defaultCheckedbooleanInitial uncontrolled checked state
onCheckedChange(checked: boolean) => voidCallback when checked state changes
indeterminatebooleanfalseDisplays indeterminate (mixed) state
disabledbooleanfalseDisables the checkbox
namestringForm field name for native form submission
valuestringValue for native form submission
requiredbooleanfalseMarks the field as required

Structure

  • CheckboxIndicator [indicator]

(expected) = recommended in canonical composition, not runtime-required.

States

StateTypeValuesDefaultCSS Reflection
disabledboolean
checkedboolean

Accessibility

  • Roles: checkbox
  • ARIA attributes: aria-checked
  • Keyboard:
    • Space to toggle
  • Notes: ARIA checkbox role and state management provided by Base UI. Supports indeterminate state via aria-checked='mixed'.

Usage

import { Checkbox, Label } from "@hareru/ui"

// Basic usage
<Checkbox />

// With a label
<div style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}>
  <Checkbox id="terms" />
  <Label htmlFor="terms">Accept terms and conditions</Label>
</div>

// Controlled
<Checkbox
  checked={accepted}
  onCheckedChange={setAccepted}
/>

// Indeterminate
<Checkbox indeterminate />

// Disabled
<Checkbox disabled defaultChecked />

Notes

  • Checkbox renders CheckboxIndicator internally — you do not need to add it manually.
  • CheckboxIndicator is exported for custom CSS styling reference.
  • Use Checkbox for deferred form selections (submitted with a form). Use Switch for immediate-effect boolean settings.
  • The underlying element is a <button type="button"> for keyboard and assistive technology support.
  • Indeterminate state is reflected as aria-checked="mixed" and [data-indeterminate] in CSS.

On this page