Skip to main content

Checkbox

Selects multiple options from a set; can be used standalone or composed with LhCheckboxGroup.

Basic usage​

Standalone and grouped

Selected: ink

import { useState } from 'react'
import { LhCheckbox, LhCheckboxGroup } from '@lh-ui/react'

export default function Demo() {
const [checked, setChecked] = useState(false)
const [group, setGroup] = useState<string[]>(['ink'])

return (
<>
<LhCheckbox checked={checked} onChange={(val) => setChecked(val)}>
Standalone checkbox
</LhCheckbox>

<LhCheckboxGroup value={group} onChange={(val) => setGroup(val as string[])}>
<LhCheckbox value="ink">Ink</LhCheckbox>
<LhCheckbox value="danqing">Danqing</LhCheckbox>
<LhCheckbox value="blank">Blank</LhCheckbox>
</LhCheckboxGroup>
</>
)
}

Checkbox Props​

PropDescriptionTypeOptionsDefault
valueOption value (effective inside a Group)unknown——
checkedControlled checked state (when used standalone)boolean——
defaultCheckedUncontrolled default checkedboolean—false
labelDisplay textstring——
disabledWhether to disableboolean—false
indeterminateIndeterminate state (visual only; produces no value)boolean—false
sizeSize'large' | 'middle' | 'small'—Follows ConfigProvider
nameNative name attribute (passed through by the Group)string——
sxShorthand layout propsSxProps——

Checkbox events​

EventDescriptionCallback signatureVue equivalent
onChangeChecked state change (two arguments)(checked: boolean, event: ChangeEvent) => void@change

CheckboxGroup Props​

PropDescriptionTypeDefault
valueControlled selected values arrayunknown[]—
defaultValueUncontrolled default valueunknown[][]
disabledDisable all childrenbooleanfalse
sizeChild size'large' | 'middle' | 'small'Follows ConfigProvider
nameNative name attribute passed through to childrenstring—

CheckboxGroup events​

EventDescriptionCallback signatureVue equivalent
onChangeSelected values array change(value: unknown[]) => void@change
Indeterminate state

indeterminate is commonly used for the intermediate state of a "select all": visually a horizontal bar, but it does not affect checked. The component syncs it to the native input.indeterminate inside useEffect.

Styles​

import '@lh-ui/react/style/checkbox'