NativeUI Primitives

Checkbox Group

Coordinate multiple checkboxes with shared state management and validation.


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

CheckboxGroup manages multiple checkboxes as a coordinated group with array-based value state.

FeatureDescriptionPlatforms
CheckboxGroupRoot container coordinating checkboxesiOS, Android, Web

Setup & Usage Guide

CheckboxGroup simplifies managing multiple checkbox selections.

1. Install and Import

Install from npm:

npm install @native-ui-org/primitives

Then import from the package:

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

2. Basic Usage

Manage multiple checkboxes as a group:

<CheckboxGroup defaultValue={['option1']}>
  <Checkbox value="option1">
    <CheckboxIndicator>
      {({ checked }) => <View style={checked ? styles.checked : styles.unchecked} />}
    </CheckboxIndicator>
    <CheckboxLabel><Text>Option 1</Text></CheckboxLabel>
  </Checkbox>
  
  <Checkbox value="option2">
    <CheckboxIndicator>
      {({ checked }) => <View style={checked ? styles.checked : styles.unchecked} />}
    </CheckboxIndicator>
    <CheckboxLabel><Text>Option 2</Text></CheckboxLabel>
  </Checkbox>
  
  <Checkbox value="option3">
    <CheckboxIndicator>
      {({ checked }) => <View style={checked ? styles.checked : styles.unchecked} />}
    </CheckboxIndicator>
    <CheckboxLabel><Text>Option 3</Text></CheckboxLabel>
  </Checkbox>
</CheckboxGroup>

3. Controlled State

Manage group state externally:

const [selected, setSelected] = useState(['option1', 'option3']);

<CheckboxGroup value={selected} onValueChange={setSelected}>
  <Checkbox value="option1">
    <CheckboxIndicator>{({ checked }) => /* ... */}</CheckboxIndicator>
    <CheckboxLabel><Text>Option 1</Text></CheckboxLabel>
  </Checkbox>
  
  <Checkbox value="option2">
    <CheckboxIndicator>{({ checked }) => /* ... */}</CheckboxIndicator>
    <CheckboxLabel><Text>Option 2</Text></CheckboxLabel>
  </Checkbox>
</CheckboxGroup>

4. Disabled Group

Disable all checkboxes at once:

<CheckboxGroup disabled>
  <Checkbox value="option1">
    <CheckboxIndicator>{({ checked }) => /* ... */}</CheckboxIndicator>
    <CheckboxLabel><Text>Option 1</Text></CheckboxLabel>
  </Checkbox>
</CheckboxGroup>

API Reference

CheckboxGroup

Container coordinating multiple checkboxes.

PropTypeDefaultDescription
valuestring[]Controlled selected values
defaultValuestring[][]Initial selected values (uncontrolled)
onValueChange(value: string[]) => voidCallback when selection changes
disabledbooleanfalseDisable all checkboxes
requiredbooleanfalseAt least one must be selected
namestringForm field name
asChildbooleanfalseUse Slot pattern

Note: Individual checkboxes inside the group use their value prop to identify themselves.


Platform Behavior

PlatformImplementationCharacteristics
iOS / AndroidContext-based state coordinationNative performance
WebFieldset with checkboxesForm compatible
All PlatformsConsistent APISame props, same behavior

Accessibility

Web:

  • Wraps in <fieldset> for semantic grouping
  • Proper keyboard navigation
  • Form validation support

Mobile:

  • Group label announced by screen readers
  • Individual checkbox states accessible

Version History

VersionNotes
0.1.0Initial release — checkbox group with array-based state management.

Summary: CheckboxGroup simplifies managing multiple checkbox selections. Use it for multi-select forms, filter options, or settings panels. Provides coordinated state management with array-based values.