Skip to Content

Checkbox

Capture boolean input from user.

Import

import { Checkbox } from '@tidbcloud/uikit'

Usage

import { Checkbox } from '@tidbcloud/uikit' function Demo() { return <Checkbox defaultChecked label="I agree to sell my privacy" /> }

Controlled

import { useState } from 'react' import { Checkbox } from '@tidbcloud/uikit' function Demo() { const [checked, setChecked] = useState(false) return <Checkbox checked={checked} onChange={(event) => setChecked(event.currentTarget.checked)} /> }

States

import { Checkbox, Stack } from '@tidbcloud/uikit' function Demo() { return ( <Stack> <Checkbox checked={false} onChange={() => {}} label="Default checkbox" /> <Checkbox checked={false} onChange={() => {}} indeterminate label="Indeterminate checkbox" /> <Checkbox checked onChange={() => {}} label="Checked checkbox" /> <Checkbox disabled label="Disabled checkbox" /> <Checkbox disabled checked onChange={() => {}} label="Disabled checked checkbox" /> </Stack> ) }

Indeterminate state

Checkbox supports indeterminate state:

import { Checkbox } from '@tidbcloud/uikit' function Demo() { return <Checkbox indeterminate label="Indeterminate checkbox" /> }
import { Checkbox, Anchor } from '@tidbcloud/uikit' function Demo() { return ( <Checkbox label={ <> I accept{' '} <Anchor href="https://mantine.dev" target="_blank" inherit> terms and conditions </Anchor> </> } /> ) }

Checkbox.Group

import { Checkbox, Group } from '@tidbcloud/uikit' function Demo() { return ( <Checkbox.Group defaultValue={['react']} label="Select your favorite frameworks" description="This is anonymous"> <Group mt="xs"> <Checkbox value="react" label="React" /> <Checkbox value="svelte" label="Svelte" /> <Checkbox value="ng" label="Angular" /> <Checkbox value="vue" label="Vue" /> </Group> </Checkbox.Group> ) }

Controlled Checkbox.Group

import { useState } from 'react' import { Checkbox } from '@tidbcloud/uikit' function Demo() { const [value, setValue] = useState<string[]>([]) return ( <Checkbox.Group value={value} onChange={setValue}> <Checkbox value="react" label="React" /> <Checkbox value="svelte" label="Svelte" /> </Checkbox.Group> ) }

Props

PropTypeDefaultDescription
checkedboolean-Checked state for controlled component
colorMantineColor-Key of theme.colors or any valid CSS color
defaultCheckedboolean-Default checked state for uncontrolled component
descriptionReact.ReactNode-Description displayed below the label
disabledboolean-Disables checkbox
errorReact.ReactNode-Error message
icon(props) => ReactNode-Custom check icon component
iconColorMantineColor-Icon color
indeterminateboolean-Indeterminate state, ignores checked prop
labelReact.ReactNode-Checkbox label
labelPosition'left' | 'right''right'Position of the label
onChange(event) => void-Called when checked state changes
radiusMantineRadius-Border radius
sizeMantineSize'sm'Checkbox size
Last updated on