Checkbox

Checkbox's allow the user to select at multiple options in a group at once.

If you have multiple checkboxes, use a Checkbox.Group to group them together with spacing.

For information on Checkboxes and Form style and usage guidelines, check out Form Selection Design Guidelines and Form Design Guidelines.

Example

A normal example of a vertical group of Checkbox components.

Using State

Checkbox comes with onChange and value event props for you to handle in any way. Here's an example of a single checkbox with React Hooks.

const [checked, setChecked] = useState(false);
const handleChange = (e) => {
setChecked(e.target.checked);
};
return (
<Checkbox id="male" value="male">
Male
</Checkbox>
)

You can use the same handler for all checkboxes through onChange in the Checkbox.Group. Not that you will need to indivdually set the checked prop of each Checkbox.

const [state, setState] = React.useState({
male: true,
female: false,
other: false,
});
const handleChange = (e) => {
setState({ ...state, e.target.id: e.target.checked });
}
return (
<Checkbox.Group
onChange={handleChange}
>
<Checkbox id="male" checked={state.male} value="male">
Male
</Checkbox>
<Checkbox id="female" checked={state.female} value="female">
Female
</Checkbox>
<Checkbox id="other" checked={state.other} value="other">
Other
</Checkbox>
</Checkbox.Group>
)

Error Handling

Use the error prop in Checkbox to define the error state of that Checkbox Component. You may choose between default, error, warning, and success. Note the style change when the Checkbox is selected.

Disabled

You can disable individual checkboxes with the disabled prop. The same applies to entire Radio Group with the disabled prop in Checkbox.Group.

Try adding it to Checkbox.Group.

Common Props

Checkbox includes COMMON common props. Checkbox.Group includes COMMON, FLEX, and BORDER props. Read Common Props for details and API. These common props will override component props such as the color.

Checkbox Component Props

Prop nameTypeDefaultDescription
checkedBooleanWhether the checkbox is selected or not.
childrenNodeThe label of the Checkbox.
defaultCheckedBooleanWhether it is initially selected or not. This should not be used when checked and onChange is used or when it's Checkbox.Group has onChange set.
disabledBooleanfalseDisable input
errordefault | error | warning | success'default'Set the error state
idStringInput ID. This should always be set for accessibility purposes.
nameStringHTML name attribute (used for grouping) - this is unnecessary to set when using Checkbox.Group.
onChangeFuncCallback to execute on user input
themeObjectBridge ThemeUse to override default bridge theme
valueAnyThe value used to compare to see if it is selected

Checkbox.Group Component Props

Prop nameTypeDefaultDescription
childrenNodeThese should be Checkbox components to be grouped together
defaultValueAnyThe default value (out of the children Checkboxs) to be selected. This should not be used when onChange are used
disabledBooleanfalseDisable input for all children
errordefault | error | warning | success'default'Set the error state for all children
themeObjectBridge ThemeUse to override default bridge theme
verticalBooleanfalseEnable vertical grouping