Checkbox
Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected.
size
isEmphasized
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, Button, Form} from '@react-spectrum/s2';
<Form>
<Checkbox
name="terms"
value="agree"
isRequired>
I agree to the terms
</Checkbox>
<Button type="submit">Submit</Button>
</Form>
API
Name | Type | Default |
---|---|---|
children | ReactNode | Default: — |
The label for the element. | ||
inputRef | RefObject | Default: — |
A ref for the HTML input element. | ||
isIndeterminate | boolean | Default: — |
Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. | ||
defaultSelected | boolean | Default: — |
Whether the element should be selected (uncontrolled). | ||
isSelected | boolean | Default: — |
Whether the element should be selected (controlled). | ||
isDisabled | boolean | Default: — |
Whether the input is disabled. | ||
isReadOnly | boolean | Default: — |
Whether the input can be selected but not changed by the user. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
size | 'S'
| 'M'
| 'L'
| 'XL' | Default: 'M'
|
The size of the Checkbox. | ||
isEmphasized | boolean | Default: — |
Whether the Checkbox should be displayed with an emphasized style. | ||
onChange |
| Default: — |
Handler that is called when the element's selection state changes. | ||