NativeUI Primitives

Checkbox

Create accessible checkboxes with custom styling and full keyboard support across all platforms.


Preview

Interactive Demo

Installation

npm install @native-ui-org/primitives
pnpm add @native-ui-org/primitives
yarn add @native-ui-org/primitives
bun add @native-ui-org/primitives

Overview

Checkbox is a compound component for building checkboxes with labels and custom indicators.

FeatureDescriptionPlatforms
CheckboxRoot container managing stateiOS, Android, Web
CheckboxIndicatorVisual checkbox state indicatoriOS, Android, Web
CheckboxLabelClickable label textiOS, Android, Web

Setup & Usage Guide

Checkbox provides the structure for accessible checkbox inputs with full control over styling.

1. Install and Import

Install from npm:

npm install @native-ui-org/primitives

Then import from the package:

import { 
  Checkbox, 
  CheckboxIndicator,
  CheckboxLabel 
} from "@native-ui-org/primitives";

2. Basic Usage

Simple checkbox with label:

<Checkbox defaultChecked={false}>
  <CheckboxIndicator>
    {({ checked }) => (
      <View style={checked ? styles.checked : styles.unchecked}>
        {checked && <Icon name="check" />}
      </View>
    )}
  </CheckboxIndicator>
  <CheckboxLabel>
    <Text>Accept terms and conditions</Text>
  </CheckboxLabel>
</Checkbox>

3. Controlled State

Manage checkbox state externally:

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

<Checkbox checked={checked} onCheckedChange={setChecked}>
  <CheckboxIndicator>
    {({ checked }) => (
      <View style={styles.indicator}>
        {checked && <Text>✓</Text>}
</View>
    )}
  </CheckboxIndicator>
  <CheckboxLabel>
    <Text>Subscribe to newsletter</Text>
  </CheckboxLabel>
</Checkbox>

4. Disabled State

<Checkbox disabled checked={true}>
  <CheckboxIndicator>
    {({ checked }) => (
      <View style={styles.indicatorDisabled}>
        {checked && <Icon name="check" color="#ccc" />}
    </View>
    )}
  </CheckboxIndicator>
  <CheckboxLabel>
    <Text style={styles.labelDisabled}>Disabled option</Text>
  </CheckboxLabel>
</Checkbox>

API Reference

Checkbox

Root container managing checkbox state.

PropTypeDefaultDescription
checkedbooleanControlled checked state
defaultCheckedbooleanfalseInitial state (uncontrolled)
onCheckedChange(checked: boolean) => voidCallback when state changes
disabledbooleanfalseDisable interactions
requiredbooleanfalseMark as required (forms)
namestringForm field name
valuestring"on"Form value when checked
asChildbooleanfalseUse Slot pattern

CheckboxIndicator

Visual indicator for checkbox state.

PropTypeDefaultDescription
childrenfunction | React.ReactNodeRender function or content
forceMountbooleanfalseKeep mounted when unchecked
asChildbooleanfalseUse Slot pattern

CheckboxLabel

Clickable label text.

PropTypeDefaultDescription
asChildbooleanfalseUse Slot pattern
...propsanyStandard Text props

Platform Behavior

PlatformImplementationCharacteristics
iOS / AndroidPressable with stateNative touch feedback
WebInput checkbox (hidden) + visualKeyboard accessible, form compatible
All PlatformsConsistent APISame props, same behavior

Accessibility

Web:

  • Hidden <input type="checkbox"> for form compatibility
  • Proper label association
  • Keyboard support (Space to toggle)
  • Focus management

Mobile:

  • Accessibility role "checkbox"
  • State announced to screen readers
  • Works with VoiceOver and TalkBack

Version History

VersionNotes
0.1.0Initial release — checkbox with label and indicator, controlled/uncontrolled states.

Summary: Checkbox provides accessible checkbox inputs with full styling control. Use it for forms, settings, multi-select lists, or any boolean input. Supports both controlled and uncontrolled modes with proper accessibility.