Checkbox

Collect user's choices.
Importimport{ Checkbox }from"antd";

When To Use

  • Used for selecting multiple values from several options.
  • If you use only one checkbox, it is the same as using Switch to toggle between two states. The difference is that Switch will trigger the state change directly, but Checkbox just marks the state as changed and this needs to be submitted.

Examples

Basic usage of checkbox.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Communicated with other components.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

The indeterminate property can help you to achieve a 'check all' effect.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code


Disabled checkbox.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code




Generate a group of checkboxes from an array.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

We can use Checkbox and Grid in Checkbox.Group, to implement complex layout.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

Checkbox

PropertyDescriptionTypeDefaultVersion
autoFocusIf get focus when component mountedbooleanfalse
checkedSpecifies whether the checkbox is selectedbooleanfalse
defaultCheckedSpecifies the initial state: whether or not the checkbox is selectedbooleanfalse
disabledIf disable checkboxbooleanfalse
indeterminateThe indeterminate checked state of checkboxbooleanfalse
onChangeThe callback function that is triggered when the state changes(e: CheckboxChangeEvent) => void-
onBlurCalled when leaving the componentfunction()-
onFocusCalled when entering the componentfunction()-

Checkbox Group

PropertyDescriptionTypeDefaultVersion
defaultValueDefault selected value(string | number)[][]
disabledIf disable all checkboxesbooleanfalse
nameThe name property of all input[type="checkbox"] childrenstring-
optionsSpecifies optionsstring[] | number[] | Option[][]
valueUsed for setting the currently selected value(string | number | boolean)[][]
onChangeThe callback function that is triggered when the state changes(checkedValue: T[]) => void-
Option
interface Option {
label: string;
value: string;
disabled?: boolean;
}

Methods

Checkbox

NameDescriptionVersion
blur()Remove focus
focus()Get focus
nativeElementReturns the DOM node of the Checkbox5.17.3

Design Token

Global TokenHow to use?

FAQ

Why not work in Form.Item?

Form.Item default bind value to value property, but Checkbox value property is checked. You can use valuePropName to change bind property.

<Form.Item name="fieldA" valuePropName="checked">
<Checkbox />
</Form.Item>