Checkbox

Whether you're building a simple form or a complex data collection system, the Checkbox component offers a user-friendly way for users to select multiple options from a list.
Installation
API Reference
This is an illustration of Checkbox component.
size
isInvalid
isDisabled
<Checkbox size="md" isInvalid={false} isDisabled={false}>
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Label</CheckboxLabel>
</Checkbox>

Installation

Run the following command:

npx gluestack-ui add checkbox

API Reference

To use this component in your project, include the following import statement in your file.
import { Checkbox } from "@/components/ui/checkbox"
export default () => (
<CheckboxGroup>
<Checkbox>
<CheckboxIndicator>
<CheckboxIcon />
</CheckboxIndicator>
<CheckboxLabel />
</Checkbox>
</CheckboxGroup>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Checkbox

Contains all Checkbox related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
value
string
-
The value to be used in the checkbox input. This is the value that will be returned on form submission.
onChange
(value: boolean) => void
-
Function called when the state of the checkbox changes.
defaultIsChecked
bool
false
If true, the checkbox will be initially checked.
isChecked
bool
false
When true, the checkbox will be checked. You'll need to pass onChange to update it's value (since it's now controlled).
isDisabled
bool
false
To manually set disable to the checkbox.
isInvalid
bool
false
To manually set invalid to the checkbox.
isReadOnly
bool
false
To manually set read-only to the checkbox.
isHovered
bool
false
To manually set hover to the checkbox.
isFocusVisible
bool
false
To manually set focus visible state to the checkbox.
isIndeterminate
bool
false
To manually set indeterminate to the checkbox.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style CheckboxLabel Component
_icon
Prop to style CheckboxIcon Component
_indicator
Prop to style CheckboxIndicator Component

CheckboxIndicator

Contains all indicators related layout style props and actions. It inherits all the properties of React Native's View component.

CheckboxIcon

Contains all Icon related layout style props and actions. It inherits all the properties of gluestack Style's AsForwarder component.

CheckboxLabel

Contains all Label related layout style props and actions. It inherits all the properties of React Native's Text component.

CheckboxGroup

Contains all Group related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
value
string[]
-
The value of the checkbox group.
onChange
(values: Array<string>) => void
-
The callback fired when any children Checkbox is checked or unchecked.
isDisabled
bool
false
To manually set disable to the checkbox.
isInvalid
bool
false
To manually set invalid to the checkbox.
isReadOnly
bool
false
To manually set read-only to the checkbox.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.

Accessibility

We have outlined the various features that ensure the Checkbox component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the WAI-ARIA design pattern.

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Shift + Tab: Moves focus to the previous focusable element.