Checkbox
The Checkbox component provides a binary choice interface that allows users to select or deselect options. It’s ideal for forms, settings, and any scenario where users need to make yes/no or on/off decisions.
Usage Guidelines
Basic Checkbox
Use the Checkbox component for binary choices in forms and settings.
<Checkbox>I agree to the terms and conditions</Checkbox>Checked State
Use the defaultSelected prop to set the initial state of the checkbox (uncontrolled), or use isSelected with onChange for controlled state.
Subscribe to newsletter
<Checkbox defaultSelected>Subscribe to newsletter</Checkbox>Controlled State
For controlled state, use isSelected with onChange to manage the checkbox state externally.
Controlled checkbox
const [checked, setChecked] = useState(false);
<Checkbox isSelected={checked} onChange={setChecked}> Controlled checkbox</Checkbox>;Disabled State
Use the isDisabled prop to prevent user interaction with the checkbox.
This option is not available
<Checkbox isDisabled>This option is not available</Checkbox>Indeterminate State
Use the isIndeterminate prop to show a partially selected state, often used for parent checkboxes that control multiple child checkboxes.
Select all items
<Checkbox isIndeterminate>Select all items</Checkbox>Without Label
You can use the Checkbox without a visible label for custom layouts.
<Checkbox />Props
The CSS className for the element. A function may be provided to compute the class based on component state.
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction.
The value of the input element, used when submitting an HTML form. See MDN.
Whether the element should be selected (uncontrolled).
Whether the element should be selected (controlled).
Handler that is called when the element's selection state changes.
Whether the input is disabled.
Whether the input can be selected but not changed by the user.
Whether user input is required on the input before form submission.
Whether the input value is invalid.
A function that returns an error message if a given value is invalid.
Validation errors are displayed to the user when the form is submitted
if validationBehavior="native". For realtime validation, use the isInvalid
prop instead.
Whether the element should receive focus on render.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
Handler that is called when a key is pressed.
Handler that is called when a key is released.
The name of the input element, used when submitting an HTML form. See MDN.
The <form> element to associate the input with.
The value of this attribute must be the id of a <form> in the same document.
See MDN.
Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
The element's unique identifier. See MDN.
Handler that is called when the press is released over the target.
Handler that is called when a press interaction starts.
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
Handler that is called when the press state changes.
Handler that is called when a press is released over the target, regardless of whether it started on the target or not.
Not recommended – use onPress instead. onClick is an alias for onPress
provided for compatibility with other libraries. onPress provides
additional event details for non-mouse interactions.
A ref for the HTML input element.
Handler that is called when a hover interaction starts.
Handler that is called when a hover interaction ends.
Handler that is called when the hover state changes.
The inline style for the element. A function may be provided to compute the style based on component state.
A slot name for the component. Slots allow the component to receive props from a parent component.
An explicit null value indicates that the local props completely override all props received from a parent.