A checkbox allows a user to select multiple items from a list of individual items, or to mark one individual item as selected.
Vanilla CSS theme
This sets the
--tint CSS variable used by the Vanilla CSS examples.Theme
isIndeterminate
isDisabled
Selection
Use the isSelected or defaultSelected prop to set the selection state, and onChange to handle selection changes. The isIndeterminate prop overrides the selection state regardless of user interaction.
You are unsubscribed
isIndeterminate
Forms
Use the name and value props to submit the checkbox to the server. Set the isRequired prop to validate the user selects the checkbox, or implement custom client or server-side validation. See the Forms guide to learn more.
import {Checkbox} from './Checkbox';
import {Button} from './Button';
import {Form} from './Form';;
<Form>
<Checkbox
name="terms"
value="agree"
isRequired>
I agree to the terms
</Checkbox>
<Button type="submit" style={{marginTop: 8}}>Submit</Button>
</Form>
API
<Checkbox>Label</Checkbox>
Checkbox
| Name | Type | |
|---|---|---|
inputRef | RefObject | |
| A ref for the HTML input element. | ||
isIndeterminate | boolean | |
| Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. | ||
defaultSelected | boolean | |
| Whether the element should be selected (uncontrolled). | ||
isSelected | boolean | |
| Whether the element should be selected (controlled). | ||
isDisabled | boolean | |
| Whether the input is disabled. | ||
isReadOnly | boolean | |
| Whether the input can be selected but not changed by the user. | ||
children | ChildrenOrFunction | |
| The children of the component. A function may be provided to alter the children based on component state. | ||
onChange | | |
| Handler that is called when the element's selection state changes. | ||
Default className: react-aria-Checkbox
| Render Prop | CSS Selector |
|---|---|
isSelected | CSS Selector: [data-selected]
|
| Whether the checkbox is selected. | |
isIndeterminate | CSS Selector: [data-indeterminate]
|
| Whether the checkbox is indeterminate. | |
isHovered | CSS Selector: [data-hovered]
|
| Whether the checkbox is currently hovered with a mouse. | |
isPressed | CSS Selector: [data-pressed]
|
| Whether the checkbox is currently in a pressed state. | |
isFocused | CSS Selector: [data-focused]
|
| Whether the checkbox is focused, either via a mouse or keyboard. | |
isFocusVisible | CSS Selector: [data-focus-visible]
|
| Whether the checkbox is keyboard focused. | |
isDisabled | CSS Selector: [data-disabled]
|
| Whether the checkbox is disabled. | |
isReadOnly | CSS Selector: [data-readonly]
|
| Whether the checkbox is read only. | |
isInvalid | CSS Selector: [data-invalid]
|
| Whether the checkbox invalid. | |
isRequired | CSS Selector: [data-required]
|
| Whether the checkbox is required. | |