Checkbox for Astro
Native Astro checkboxes for independent choices and form values.
Installation
bunx --bun shadcn@latest add @gnostic/checkboxnpx shadcn@latest add @gnostic/checkboxpnpm dlx shadcn@latest add @gnostic/checkboxCopy the files
src/components/ui/checkbox/checkbox.astrosrc/components/ui/checkbox/index.ts
Usage
import { Checkbox } from "@/components/ui/checkbox"
<Checkbox />
Notes
- Pair
CheckboxwithLabelfor simple cases, or use Field when you need descriptions, validation, or grouped controls. - Use the native
disabledattribute to prevent interaction andaria-invalidwhen the control should display an error state. - For multi-line rows, wrap the label and supporting text together so the control stays easy to scan.
API Reference
Read the installed source for the complete prop types.
When to use Checkbox
Pair each Checkbox with a Label using matching id and for values. Give submitted controls a name and value. Use separate checkboxes when several choices can be selected together.
Keyboard and behavior
The rendered input uses native form submission, focus, Space activation, and disabled behavior. Set the DOM indeterminate property from your script for a mixed selection; an HTML attribute alone cannot set that property. A parent “select all” checkbox does not manage child values automatically.
Theme and layout
Checked, invalid, and disabled styles use the shared tokens. The check mark is a CSS mask on the input. Keep a text label visible and use FieldError for an explanation of invalid input.