JGuang

Checkbox

Checkbox · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Checkbox

Make multiple selections in a set of options.

Install

npm install antd-mobile@5.43.0

antd-mobile is for mobile web, not React Native or Mini Programs. React 19 projects must register createRoot with unstableSetRender at the entry, or imperative APIs such as Toast and Dialog cannot render. Switch dark mode with <html data-prefers-color-scheme="dark">.

Examples come from the official Ant Design Mobile repository (MIT) at the commit published as npm 5.43.0. Presentation helpers such as DemoBlock are JGuang rewrites, not antd-mobile APIs.

Make multiple selections in a set of options.

When to Use

  • When making multiple selections from a set of options.
  • Used alone to indicate a switch between two states, similar to switch. The difference is that switching the switch will directly trigger the state change, while the checkbox is generally used for state marking and needs to cooperate with the submit operation.

Demos

Checkbox

Props

type CheckboxValue = string | number
NameDescriptionTypeDefault
blockWhether to render as a block-level elementbooleanfalse
checkedTo specify whether selected or not currentlybooleanfalse
defaultCheckedSelected or not initiallybooleanfalse
disabledDisabled statebooleanfalse
iconThe customized icon(checked: boolean, indeterminate: boolean) => React.ReactNode-
idThe id of the input element, often used in conjunction with the labelstring-
indeterminateTo set the indeterminate state, only responsible for style controlbooleanfalse
onChangeCallback function when changing(val: boolean) => void-
onClickCheckbox's click event(event: React.MouseEvent<HTMLLabelElement, MouseEvent>) => void-
valueThe value carrying identification, used in Group modeCheckboxValue-

Ref

NameDescriptionType
checkTrigger the check of the Checkbox() => void
uncheckTrigger the uncheck of the Checkbox() => void
toggleTrigger the checked state toggle of the Checkbox() => void

CSS Variables

NameDescriptionDefault
--font-sizeFont size of the description label.17px
--gapThe gap between the check icon and the description label.8px
--icon-sizeSize of the check icon.22px

Checkbox.Group

Props

NameDescriptionTypeDefault
defaultValueOptions selected by defaultCheckboxValue[][]
disabledTo make whole group failurebooleanfalse
onChangeCallback function when changing(value: CheckboxValue[]) => void-
valueTo specify the selected optionCheckboxValue[][]