Skip to content

Checkbox ​

Checkbox input with label and indeterminate state support.

Also known as: check box, tick box, boolean toggle

View in Storybook

When to use ​

  • Binary on/off choices. For selecting from multiple options, use CheckboxGroup.
  • For card-style selection, use CheckboxCard. For mutual exclusion, use Radio.

Import ​

tsx
import { Checkbox } from '@vacano/ui'

Usage ​

tsx
const [checked, setChecked] = useState(false)

<Checkbox
  checked={checked}
  onChange={(e) => setChecked(e.target.checked)}
  label="Accept terms"
/>

With Label ​

tsx
<Checkbox checked={true} onChange={() => {}} label="Remember me" />

Indeterminate State ​

Used for "select all" scenarios where some items are selected:

tsx
<Checkbox
  checked={false}
  indeterminate={true}
  onChange={() => {}}
  label="Select all"
/>

Variants ​

tsx
<Checkbox variant="normal" checked={true} onChange={() => {}} label="Normal" />
<Checkbox variant="error" checked={true} onChange={() => {}} label="Error" />

Disabled ​

tsx
<Checkbox disabled checked={true} onChange={() => {}} label="Disabled checked" />
<Checkbox disabled checked={false} onChange={() => {}} label="Disabled unchecked" />

Props ​

PropTypeDefaultDescription
checkedbooleanrequiredChecked state
onChangeChangeEventHandler<HTMLInputElement>requiredChange handler
labelReactNode-Label content (text or any renderable node)
indeterminatebooleanfalseIndeterminate state
variant'normal' | 'error''normal'Visual variant
disabledbooleanfalseDisable checkbox
classNamestring-CSS class name for the root element
classnamesCheckboxClassNames-Custom class names for inner elements
refRef<HTMLInputElement>-Ref to the underlying input element
data-test-idstring-Test identifier attribute

All standard HTML input attributes are also supported (except type, checked, onChange, and className which are controlled by the component).

ClassNames ​

KeyDescription
inputHidden input element
boxVisual checkbox box
iconCheck icon
labelLabel text

Released under the MIT License.