Overview
Checkbox provides a binary or tristate control that users can check or uncheck. It supports an indeterminate state for partial selections and can be used in forms or as a standalone control.Features
- Supports indeterminate state
- Can be controlled or uncontrolled
- Full keyboard navigation
- Works inside forms
- Accessible by default with proper ARIA attributes
- Custom styling with data attributes
Installation
Anatomy
API Reference
Root
Contains all the checkbox component parts. Aninput will also render when used within a form to ensure events propagate correctly.
The controlled checked state of the checkbox.
The checked state when initially rendered (uncontrolled).
Event handler called when the checked state changes.
When true, prevents the user from interacting with the checkbox.
When true, indicates that the user must check the checkbox before submitting the form.
The name of the checkbox. Submitted with its owning form as part of a name/value pair.
The value given as data when submitted with a name.
Change the default rendered element for the one passed as a child.
Indicator
Renders when the checkbox is in a checked or indeterminate state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
Change the default rendered element for the one passed as a child.
Example
Accessibility
Adheres to the tri-state Checkbox WAI-ARIA design pattern.
Keyboard Interactions
- Space - Toggles the checkbox.
Data Attributes
Root[data-state]- “checked”, “unchecked”, or “indeterminate”[data-disabled]- Present when disabled
[data-state]- “checked”, “unchecked”, or “indeterminate”[data-disabled]- Present when disabled