Checkbox
A checkbox turns one option on or off, or picks several options from a list.
When to use
Section titled “When to use”- Use it for agreements and for choosing several items.
- Use a radio group or a Select when only one choice is allowed.
- Don’t use it for settings that apply at once; use a switch.
Anatomy
Section titled “Anatomy”- 1Checked box on primary
- 2Unchecked box
- 3Label, also clickable
A 16px box on radius-sm (6px) with a check icon, and a label beside it. Checked boxes fill with primary.
Variants
Section titled “Variants”There is one style. A checkbox can be checked, unchecked or indeterminate.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
checked / defaultChecked |
v-model / default-value |
value |
boolean | false |
The state. |
onCheckedChange |
@update:model-value |
onChanged |
function | none | Runs when the state changes. |
disabled |
disabled |
enabled: false |
boolean | false |
Blocks changes. |
id |
id |
label |
string | none | Links the label. |
import { Checkbox } from "@/components/ui/checkbox"import { Label } from "@/components/ui/label"
export default function CheckboxDemo() { return ( <div className="flex items-center gap-2"> <Checkbox id="checkbox-demo-terms" /> <Label htmlFor="checkbox-demo-terms">Saya setuju dengan syarat penggunaan</Label> </div> )}<script setup lang="ts">import { Checkbox } from "@/components/ui/checkbox"import { Label } from "@/components/ui/label"</script>
<template> <div class="flex items-center gap-2"> <Checkbox id="checkbox-demo-terms-vue" /> <Label for="checkbox-demo-terms-vue">Saya setuju dengan syarat penggunaan</Label> </div></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class CheckboxDemo extends StatefulWidget { const CheckboxDemo({super.key});
@override State<CheckboxDemo> createState() => _CheckboxDemoState();}
class _CheckboxDemoState extends State<CheckboxDemo> { bool agreed = false;
@override Widget build(BuildContext context) { return ShadCheckbox( value: agreed, onChanged: (value) => setState(() => agreed = value), label: const Text('Saya setuju dengan syarat penggunaan'), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/checkbox.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/checkbox.jsonAccessibility
Section titled “Accessibility”- Renders
role="checkbox"witharia-checked; Space toggles it. - Every checkbox needs a label, linked by
id.
