suiss/ui · Component
Checkbox
A control that lets people turn a single option on or off.
Checkbox is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Checkbox wraps the checkbox primitive and renders a check icon inside its indicator when checked. It is a single self-contained part: there are no child components to compose.
Use a checkbox for independent options that people can select in any combination, such as accepting terms or opting in to email. For a mutually exclusive choice, use a radio group; for a setting that takes effect immediately, consider a switch.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
Checked
Use defaultChecked to start the checkbox checked.
With label
Wrap the checkbox in a Label so that clicking the label text toggles it.
With description
Give the checkbox an id that a Label points to with htmlFor, and an aria-describedby that points to the description element.
Disabled
Set disabled to make a checkbox, unchecked or checked, ignore clicks and leave the Tab order.
Invalid
Set aria-invalid to show a validation error.
Set isInvalid to show a validation error.
Accessibility
- Renders with the
checkboxrole and exposes its checked state to assistive technology. - Toggles on click and with Space when focused.
- Needs an accessible name: wrap it in a
Label, associate aLabelthroughhtmlForandid, or setaria-label. - When
disabled, it setsaria-disabled, ignores clicks, and is removed from the Tab order.
- Set
aria-invalidto communicate a validation error; the border turns to thedestructivecolor.
- Set
isInvalidto communicate a validation error.
API Reference
Checkbox
The checkbox control, rendering the box and its check indicator.
| Prop | Type | Default |
|---|---|---|
checked | boolean | — |
defaultChecked | boolean | — |
onCheckedChange | (checked: boolean) => void | — |
disabled | boolean | — |
Also accepts the props of the primitive part it wraps.
Leave the checkbox uncontrolled with defaultChecked, or control it with checked and onCheckedChange.
The props map to React Aria: checked to isSelected, defaultChecked to defaultSelected and disabled to isDisabled. onCheckedChange is called with the new checked state, alongside onChange.
The hit area extends beyond the visible box through an after pseudo-element, so the small control is easier to tap. The root sets data-slot="checkbox" and the indicator data-slot="checkbox-indicator" for styling.
Web preview
Checkbox is a Pressable with the checkbox role that shows a check icon when checked and a minus icon when indeterminate. It has an enlarged hit area around the box so it is easy to tap.
Use it for options that can be combined, such as terms acceptance or multi-select lists. For a single on/off setting that applies right away, use Switch.
Installation
- Install the following dependencies:
-
Add the pieces it builds on: Icon.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/checkbox.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Icon.
-
Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/checkbox.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/checkbox.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Checked
Starts checked.
Web preview
With label
Give the label a nativeID and the checkbox a matching accessibilityLabelledBy, and toggle the value from the label's onPress.
Linked to a Label that also toggles it.
Web preview
With description
A label with a supporting description.
Web preview
Disabled
Disabled checkboxes in both states.
Web preview
Indeterminate
A select-all checkbox in the indeterminate state, for a parent whose children are partly selected.

Invalid
Set invalid to show a destructive border on a required checkbox.
Web preview
Accessibility
- Has the
checkboxrole withchecked(ormixedwhen indeterminate) anddisabledstate. - Link it to a visible label with
accessibilityLabelledBy, or give it anaccessibilityLabel.
API Reference
Checkbox
The checkbox control, rendering the box and its check indicator.
| Prop | Type | Default |
|---|---|---|
iconClassName | string | - |
invalid | boolean | - |
Also accepts the props of React.ComponentProps<typeof CheckboxPrimitive.Root>.
Use checked with onCheckedChange for controlled state, or defaultChecked for uncontrolled. Set indeterminate for a parent checkbox whose children are partly selected. iconClassName adds classes to the check icon, and invalid shows a destructive border. In dark mode the unchecked box is filled instead of outlined.
.toggleStyle(.checkbox)
Style that creates CheckboxStyle.
Takes no parameters.
Checkbox
The checkbox control, rendering the box and its check indicator.
| Parameter | Type | Default |
|---|---|---|
checked | Boolean | - |
onCheckedChange | ((Boolean) -> Unit)? | - |
modifier | Modifier | Modifier |
enabled | Boolean | LocalFieldState.current.enabled |
invalid | Boolean | LocalFieldState.current.invalid |
interactionSource | MutableInteractionSource? | null |
TriStateCheckbox
| Parameter | Type | Default |
|---|---|---|
state | ToggleableState | - |
onClick | (() -> Unit)? | - |
modifier | Modifier | Modifier |
enabled | Boolean | LocalFieldState.current.enabled |
invalid | Boolean | LocalFieldState.current.invalid |
interactionSource | MutableInteractionSource? | null |
