PeakUI

Checkbox

Selectable box with label and indicator

Usage

import {Checkbox} from "@peakui/react";

Anatomy

<Checkbox>
  <Checkbox.Content>
    <Checkbox.Control>
      <Checkbox.Indicator />
    </Checkbox.Control>
    Label text
  </Checkbox.Content>
</Checkbox>

Examples

Variants

Indeterminate

Disabled

Invalid

Controlled

Customization

Tailwind CSS

<Checkbox className="w-full">
  <Checkbox.Content>
    <Checkbox.Control>
      <Checkbox.Indicator />
    </Checkbox.Control>
    Label text
  </Checkbox.Content>
</Checkbox>

Global CSS

.checkbox {
  --checkbox-control-bg: var(--default);
}

Styling Reference

CSS Classes

ClassDescription
.checkboxThe field wrapper element
.checkbox--primary, .checkbox--secondaryVariant modifiers
.checkbox__contentThe clickable label wrapping control and text
.checkbox__controlThe square box the indicator sits in
.checkbox__indicatorThe indicator container

Slots

SlotDescription
[data-slot="checkbox"]The field wrapper element
[data-slot="checkbox-content"]The clickable label element
[data-slot="checkbox-control"]The square box element
[data-slot="checkbox-indicator"]The indicator container element
[data-slot="checkbox-default-indicator--checkmark"]The default checkmark SVG
[data-slot="checkbox-default-indicator--indeterminate"]The default indeterminate line SVG

CSS Variables

VariablePurpose
--checkbox-control-bgUnselected background of the secondary variant control

Interactive States

The component supports both CSS pseudo-classes and data attributes:

StateAttribute
Selected[data-selected="true"]
Indeterminate[data-indeterminate="true"]
Hovered[data-hovered="true"]
Pressed[data-pressed="true"]
Focused (visible)[data-focus-visible="true"]
Disabled[data-disabled="true"]
Invalid[data-invalid="true"]

API Reference

Checkbox.Root

PropTypeDefaultDescription
variant"primary" | "secondary""primary"Visual variant; inherited from the group when unset
namestring-The name used when submitting an HTML form
isSelectedboolean-Controlled selected state
defaultSelectedboolean-Uncontrolled initial selected state
isIndeterminateboolean-Indeterminate state
isDisabledboolean-Disables the checkbox
isInvalidboolean-Marks the checkbox invalid
isRequiredboolean-Marks the checkbox required
validate(isSelected) => boolean | string-Validation function
onChange(isSelected) => void-Called when the selected state changes
renderDOMRenderFunction<'div', CheckboxFieldRenderProps>-Replaces the rendered element
...restEvery React Aria CheckboxField attribute is accepted

Checkbox.Content

PropTypeDefaultDescription
renderDOMRenderFunction<'label', CheckboxButtonRenderProps>-Replaces the rendered label element
...restEvery React Aria CheckboxButton attribute is accepted

Checkbox.Control

PropTypeDefaultDescription
renderDOMRenderFunction<'span', undefined>-Replaces the rendered element

Checkbox.Indicator

PropTypeDefaultDescription
childrenReactNode | ((state) => ReactNode)default SVGsCustom indicator; receives the field render props
renderDOMRenderFunction<'span', undefined>-Replaces the rendered element

Render Props

children and className of Checkbox.Root and Checkbox.Content accept a function receiving the respective React Aria render props.

On this page