Checkbox
Check boxes are usually used in groups. Allow users to select one or more values from a set.
Import
import { Checkbox, CheckboxGroup } from 'rsuite';Examples
Basic
Disabled and read only
Use the disabled prop to disable a checkbox or readOnly to make it read-only, preventing user interaction.
Indeterminate
The indeterminate property sets the Checkbox to an indeterminate state, mainly used in the select all or tree structure Checkbox.
Colors
Customize checkbox colors using the color property. Supports preset theme colors.
Checkbox Group
Use <CheckboxGroup> to manage a group of checkboxes. The value prop controls which options are selected.
Inline Layout
Add the inline prop to <CheckboxGroup> to arrange checkboxes horizontally instead of vertically.
Checkbox Group (Controlled)
Manage checkbox group state with the value and onChange props for controlled component behavior.
Accessibility
ARIA properties
- The
roleproperty of the CheckboxGroup isgroup. - The
roleproperty of each Checkbox ischeckbox. - If the Checkbox is disabled, set
aria-disabledtotrue. - If the Checkbox is checked, set
aria-checkedtotrue, otherwise set it tofalse. - When partially checked, it has state
aria-checkedset to mixed. - A visible label referenced by the value of
aria-labelledbyset on the element with rolecheckbox.
Keyboard interaction
- When the Checkbox has focus, pressing the Space key changes the state of the Checkbox.
Props
<Checkbox>
| Property | Type (default) |
Description | Version |
|---|---|---|---|
| as | ElementType(div) |
Custom element type for the component | |
| checked | boolean | Specifies whether the checkbox is selected | |
| color | Color | The color of the checkbox when checked or indeterminate | |
| defaultChecked | boolean | Specifies the initial state: whether or not the checkbox is selected | |
| disabled | boolean | Whether disabled | |
| indeterminate | boolean | When being a checkbox , setting styles after the child part is selected | |
| inputRef | Ref | Ref of input element | |
| name | string | Used for the name of the form | |
| onChange | (value: string | number, checked: boolean, event) => void | Callback fired when checkbox is triggered and state changes | |
| title | string | HTML title | |
| value | string | number | Correspond to the value of CheckboxGroup, determine whether to select |
<CheckboxGroup>
| Property | Type (default) |
Description |
|---|---|---|
| defaultValue | string[] | number[] | The default value |
| inline | boolean | Inline layout |
| name | string | Used for the name of the form |
| onChange | (value:string[] | number[], event) => void | Callback fired when checkbox is triggered and state changes |
| value | string[] | number[] | Value of checked box (Controlled) |
Type Definitions
Color
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';