# Checkbox (/docs/native/components/checkbox)

<Preview id="checkbox/colours" title={null} />

## Installation [#installation]

<ComponentInstall name="checkbox" />

## Usage [#usage]

```tsx title="app/index.tsx"
import { Checkbox } from "@/components/ui/checkbox";
import { useState } from "react";
import { View } from "react-native";

export default function Example() {
  const [accepted, setAccepted] = useState(false);

  return (
    <View className="flex-1 items-center justify-center p-4">
      <Checkbox isChecked={accepted} onCheckedChange={setAccepted}>
        <Checkbox.Label>Accept the terms</Checkbox.Label>
      </Checkbox>
    </View>
  );
}
```

## Colours [#colours]

`color` paints the ticked indicator — an unticked box is the same chrome at all six.

<Preview id="checkbox/colours" />

```tsx
<Checkbox color="default" />
<Checkbox color="primary" />
<Checkbox color="success" />
<Checkbox color="warning" />
<Checkbox color="destructive" />
<Checkbox color="info" />
```

## Sizes [#sizes]

The box reads `--spacing-icon-*` two steps above its own glyph: 18/14, 20/16, 24/18.

<Preview id="checkbox/sizes" />

```tsx
<Checkbox size="sm" />
<Checkbox size="md" />
<Checkbox size="lg" />
```

## Indeterminate [#indeterminate]

`isIndeterminate` paints the surface, swaps the glyph and reports `checked="mixed"` — so a "select
all" row says what it means rather than claiming a half-truth.

<Preview id="checkbox/indeterminate" />

```tsx
<Checkbox isIndeterminate isChecked={all} onCheckedChange={toggleAll}>
  <Checkbox.Label>Select all</Checkbox.Label>
</Checkbox>
```

## Groups [#groups]

`Checkbox.Group`'s state is one array of the children's `value`s.

<Preview id="checkbox/checkbox-group" />

```tsx
<Checkbox.Group checked={selected} onChecked={setSelected}>
  <Checkbox value="email"><Checkbox.Label>Email</Checkbox.Label></Checkbox>
  <Checkbox value="push"><Checkbox.Label>Push</Checkbox.Label></Checkbox>
</Checkbox.Group>
```

The group carries shared defaults for the paint and state axes, which resolve
`own ?? group ?? field ?? default`.

<Callout type="warn">
Inside a group, a checkbox's `value` is required — the group tracks selection by it. A box without
one is invisible to the group's `checked` array, so it renders but never reports.
</Callout>

## Inside a field [#inside-a-field]

The box hands its toggle back up, so a form checkbox can be a bare `<Checkbox />` with
`Field.Label` naming it and the whole row driving it.

```tsx
<Field orientation="horizontal">
  <Field.Label>Accept the terms</Field.Label>
  <Checkbox isChecked={accepted} onCheckedChange={setAccepted} />
</Field>
```

Use `Field.Label` in a horizontal `Field`, and `Checkbox.Label` everywhere else.

## API Reference [#api-reference]

### Checkbox [#checkbox]

A checkbox is a `Pressable`, so `feedback`, `haptic` and the rest are inherited — see
[Pressable](/docs/native/components/pressable). `onPress` is withheld in favour of
`onCheckedChange`, and `disabled` in favour of `isDisabled`, which the label reads through context.

<TypeTable
  type={{
    isChecked: { type: "boolean", description: "Controlled. Pair with `onCheckedChange`." },
    defaultChecked: { type: "boolean", description: "The starting state while uncontrolled." },
    onCheckedChange: { type: "(isChecked: boolean) => void" },
    isIndeterminate: {
      type: "boolean",
      description: "Draws a dash rather than a tick and reports `mixed` to a screen reader — a parent row over children only partly selected.",
    },
    value: {
      type: "string",
      description: "Identifies this box to an enclosing `Checkbox.Group`. Required inside one, ignored outside.",
    },
    color: {
      type: '"default" | "primary" | "success" | "warning" | "destructive" | "info"',
      default: '"default"',
    },
    size: { type: '"sm" | "md" | "lg"', default: '"md"' },
    alignment: {
      type: '"start" | "end"',
      default: '"start"',
      description: "Which side of the label the box sits on.",
    },
    isInvalid: { type: "boolean", description: "Read from an enclosing `Field` when unset." },
    isDisabled: { type: "boolean" },
    className: { type: "string" },
    children: { type: "ReactNode", description: "Bare strings are wrapped in a `Checkbox.Label` automatically." },
  }}
/>

### Checkbox.Group [#checkboxgroup]

Owns the selection for the boxes inside it, and publishes the shared axes so each one does not
restate them. Extends `ViewProps`.

<TypeTable
  type={{
    checked: { type: "string[]", description: "Controlled. The `value` of each checked box." },
    defaultChecked: { type: "string[]" },
    onChecked: { type: "(checked: string[]) => void" },
    color: { type: '"default" | "primary" | "success" | "warning" | "destructive" | "info"' },
    size: { type: '"sm" | "md" | "lg"' },
    alignment: { type: '"start" | "end"' },
    isInvalid: { type: "boolean" },
    isDisabled: { type: "boolean", description: "Blocks every box. A box's own prop still overrides it." },
    className: { type: "string" },
    children: { type: "ReactNode" },
  }}
/>

### Checkbox.Label [#checkboxlabel]

The checkbox's text, wired as its accessible name. Extends React Native's `TextProps`.

<TypeTable type={{ className: { type: "string" }, children: { type: "ReactNode" } }} />
