Please use FormControl to display accessible checkboxes in the UI. This Checkbox
component is intended only as an ingredient for other custom components, or as a drop-in replacement for native HTML checkboxes outside of form use-cases.
If you intend to use this component as part of another component, it should always be accompanied by a corresponding <label>
to improve support for assistive technologies.
The Checkbox
component can be used in controlled and uncontrolled modes.
An indeterminate
checkbox state should be used if the input value is neither true
nor false
. This can be useful in situations where you are required to display an incomplete state, or one that is dependent on other input selections to determine a value.
Apply an optional border using FormControl
and hasBorder
.
Checkbox
provides a React alternative to the native HTML <input type="checkbox">
.
The component API supports all standard HTML attribute props, while providing some additional behavior as described below.
Name | Type | Default | Description |
---|---|---|---|
checked | boolean | Modifies true/false value of the native checkbox | |
className | string | Sets a custom class | |
defaultChecked | boolean | Checks the input by default in uncontrolled mode | |
disabled | boolean | Modifies the native disabled state of the native checkbox | |
id | string | Sets a custom id | |
indeterminate | boolean | Applies an indeterminate state to the checkbox | |
ref | React.RefObject | Forward a Ref to the underlying DOM node | |
validationStatus | 'error' 'success' | Ussed to inform ARIA attributes. Individual checkboxes do not have validation styles. |
Additional props can be passed to the <input>
element. See MDN for a list of props accepted by the <input>
element.