JGuang

Checkbox

Checkbox · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Checkbox

In a set of data, the user can select one or more items through the Checkbox.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: Basic usage.
  • Disabled: Disable the checkbox.
  • Controlled: Control whether the check box is selected
  • Checkbox group: Generate a group of checkboxes. If direction is vertical, the vertical checkbox group will be displayed.
  • Check all: The indeterminate effect can be achieved with indeterminate=true
  • Layout: We can use Checkbox and Grid in Checkbox.Group, to implement complex layout.
  • Custom Icon: Customize the selected icon through the icon property.
  • Custom Render Checkbox: Render nodes can be customized by passing a function of type 'children'( v2.29.0)。.
  • useCheckbox: useCheckbox hook offers an efficient way to manage checkbox state.

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

Checkbox

T = string | number

PropertyDescriptionTypeDefaultValueVersion
checkedWhether the checkbox is checkedboolean--
defaultCheckedTo set default checkedboolean--
disabledWhether to disableboolean--
errorWhether to show in error styleboolean--
indeterminateThe indeterminate state of checkboxboolean--
iconCustom IconCheckReactNode-2.43.0
classNameAdditional css classstring | string[]--
styleAdditional styleCSSProperties--
valueTo set checkbox valueT--
onChangeCallback when the state changes(checked: boolean, e: Event) => void--

Checkbox.Group

PropertyDescriptionTypeDefaultValue
disabledWhether to disable all checkboxes in the groupboolean-
directionArrangement direction'horizontal' | 'vertical'horizontal
classNameAdditional css classstring | string[]-
defaultValueInitial selected valueT[]-
optionsSpecifies options(T | { label: ReactNode; value: T; disabled?: boolean; icon?: ReactNode })[]-
styleAdditional styleCSSProperties-
valueTo set valueT[]-
onChangeCallback when the state changes(value: T[], e: Event) => void-

Checkbox.useCheckbox

/** T = string | number */
const result: ResultType = Checkbox.useCheckbox<T>(values: T[], defaultSelected?: T[]);

ResultType

PropertyDescriptionType
selectedCurrently selected itemsT[]
setSelectedOnly select the incoming options(value: T[]) => void;
setValueSelectedSet the checked state of the Checkbox, the second param is the state to be set.(value: T | T[], selected?: boolean) => void;
selectAllSelected all checkboxes() => void;
unSelectAllUnselected all checkboxes() => void;
isSelectedWhether the option is selected(value: T) => boolean;
toggleToggle checked state. When no params, the checked state of all options will be switched(value?: T | T[]) => void;
isAllSelectedWhether all options are selected() => boolean;
isPartialSelectedWhether only some options are selected() => boolean;