Checkbox

Animated checkbox, as a row or a selectable card.

A checkbox with an animated tick, on its own or as a selectable card.

variant="card" turns the whole surface into the target, for pickable options where the box confirms a choice rather than being the only thing to press.

Use it for a form value the reader is setting. For picking several rows out of a list, use SelectionMode — its marker is round, which is the convention for choosing rather than filling in.

Installation

Checkbox ships with the library — no separate install.

import { Checkbox } from 'panelui-native';

Or copy the source into your project, to own and edit it:

npx panelui-cli@latest add checkbox

Usage

<Checkbox
  checked={accepted}
  onCheckedChange={setAccepted}
  label="Marketing & promotions"
  description="Special offers and exclusive deals"
/>

<Checkbox
  variant="card"
  checked={plan === 'pro'}
  onCheckedChange={() => setPlan('pro')}
  label="Pro"
  description="Advanced analytics and priority support."
/>

Examples

Controlled

checked is required — the checkbox holds no state of its own.

const [accepted, setAccepted] = useState(false);

<Checkbox
  checked={accepted}
  onCheckedChange={setAccepted}
  label="I accept the terms"
/>

With a description

The description sits under the label and stays part of the press target.

<Checkbox
  checked={marketing}
  onCheckedChange={setMarketing}
  label="Product updates"
  description="Occasional email about new releases. No more than once a month."
/>

Card variant

A bordered surface that fills its width — for a list of options where each is a real choice rather than a small toggle.

<View className="gap-2">
  {plans.map((plan) => (
    <Checkbox
      key={plan.id}
      variant="card"
      checked={selected.includes(plan.id)}
      onCheckedChange={() => toggle(plan.id)}
      label={plan.name}
      description={plan.summary}
    />
  ))}
</View>

A select-all row

The header is indeterminate when the selection is a partial one — some children on, some off — and pressing it turns them all on.

const all = selected.length === items.length;
const some = selected.length > 0 && !all;

<Checkbox
  checked={all}
  indeterminate={some}
  onCheckedChange={(next) => setSelected(next ? items.map((i) => i.id) : [])}
  label={all ? 'Deselect all' : 'Select all'}
/>

Sharing a line

The label fills the rest of the row by default, so a link placed beside the checkbox gets pushed to the edge and the empty space toggles the box. contentClassName="flex-none" sizes the label to its text, and only the box and the words toggle.

<View className="flex-row items-center justify-between">
  <Checkbox
    checked={remember}
    onCheckedChange={setRemember}
    label="Remember me"
    contentClassName="flex-none"
  />
  <Button variant="ghost" size="sm" onPress={resetPassword}>
    Forgot password?
  </Button>
</View>

label takes text nodes as well as a string. A nested Text with its own onPress opens the link without toggling the box. A screen reader cannot use a node as the checkbox's name, so pass accessibilityLabel alongside it.

<Checkbox
  checked={agreed}
  onCheckedChange={setAgreed}
  accessibilityLabel="I agree to the Terms and Privacy Policy"
  label={
    <>
      I agree to the{' '}
      <Text className="text-primary underline" onPress={openTerms}>
        Terms
      </Text>{' '}
      and{' '}
      <Text className="text-primary underline" onPress={openPrivacy}>
        Privacy Policy
      </Text>
    </>
  }
/>

Styling the label

className styles the row, not the text inside it: React Native does not pass a text colour down from a view. Colour or size the label with labelClassName, and the description with descriptionClassName.

<Checkbox
  variant="card"
  checked={express}
  onCheckedChange={setExpress}
  label="Express delivery"
  description="Arrives tomorrow"
  className="bg-white"
  labelClassName="text-black"
  descriptionClassName="text-neutral-500"
/>

Variants

size

  • xs
  • sm
  • md (default)
  • lg
  • xl
<Checkbox size="xs" checked={on} onCheckedChange={setOn} label="Extra small" />
<Checkbox size="sm" checked={on} onCheckedChange={setOn} label="Small" />
<Checkbox size="md" checked={on} onCheckedChange={setOn} label="Medium" />
<Checkbox size="lg" checked={on} onCheckedChange={setOn} label="Large" />
<Checkbox size="xl" checked={on} onCheckedChange={setOn} label="Extra large" />

variant

  • default (default)
  • card
<Checkbox variant="default" checked={a} onCheckedChange={setA} label="Default" />

{/* A bordered surface that fills its width. */}
<Checkbox
  variant="card"
  checked={b}
  onCheckedChange={setB}
  label="Card"
  description="For options that are real choices, not small toggles."
/>

API Reference

Checkbox

PropTypeDefaultDescription
classNamestring—Styles the pressable row — layout, border, fill. It does not reach the label: text colour is not inherited from a view in React Native, so use labelClassName for that.
checkedboolean—
onCheckedChange(checked: boolean) => void—
indeterminateboolean—A third, in-between state for a box that governs a group of others — some on, some off. It fills like a checked box but shows a dash rather than a tick, and announces itself as mixed to a screen reader. Pressing it resolves the ambiguity by turning the whole group on, so the press reports true. indeterminate overrides checked for what is drawn.
disabledboolean—
labelReactNode—Optional label rendered next to the box; pressing it also toggles. A string is the usual case. Pass text nodes instead to put a link inside the sentence — <>I agree to the <Text onPress={open}>Terms</Text></> — and the link's own press wins over the toggle. A screen reader cannot read a node as the checkbox's name, so pass accessibilityLabel with it.
labelClassNamestring—Classes for the label text, merged over the defaults — e.g. text-black.
contentClassNamestring—Classes for the view holding the label and description, merged over flex-1 gap-0.5. The default makes the text fill the row; pass flex-none to size it to the text when the checkbox shares a line with other content, such as a "Forgot password" link.
descriptionstring—Secondary line under the label, for extra context.
descriptionClassNamestring—Classes for the description text, merged over the defaults.

Every part also accepts the underlying React Native props (ViewProps or TextProps) and a className for Tailwind utilities.

Notes

With a description the row aligns the box to the label rather than centring it against the whole block. The card variant moves the box after the content so it sits top-right, and takes the primary border when checked.

The indeterminate state

indeterminate is the third state a parent box needs when it governs a group whose children are partly on. It fills like a checked box but draws a dash instead of a tick, and announces itself to a screen reader as mixed rather than a plain boolean. indeterminate overrides checked for what is drawn; pressing an indeterminate box resolves the group by turning it fully on, so the press reports true.

Public exports

Values: Checkbox

Types: CheckboxProps, CheckboxSize

On this page