Checkbox
Basic Usage
---import Checkbox from '@uicg/cli/components/Checkbox/checkbox.astro'---
<Checkbox label="Accept terms and conditions" /><Checkbox checked label="Default checked" /><Checkbox indeterminate label="Indeterminate state" />Intent Variants
<Checkbox intent="default" label="Default checkbox" checked /><Checkbox intent="primary" checked label="Primary checkbox" /><Checkbox intent="success" checked label="Success checkbox" /><Checkbox intent="warning" checked label="Warning checkbox" /><Checkbox intent="danger" checked label="Danger checkbox" />Sizes
Compact size for dense interfaces
Default size for most applications
Larger size for touch interfaces or prominence
States
Default state when not selected
Active/selected state
Partially selected state, often used in tree structures
Must be checked to proceed
Cannot be interacted with
Locked in checked state
Form Integration
Properties
| Property | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | Whether the checkbox is checked |
indeterminate | boolean | false | Whether the checkbox is in an indeterminate state |
disabled | boolean | false | Whether the checkbox is disabled |
required | boolean | false | Whether the checkbox is required (shows asterisk) |
size | 'small' | 'medium' | 'large' | 'medium' | Size variant of the checkbox |
intent | 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'default' | Visual intent/state of the checkbox |
label | string | - | Label text for the checkbox |
description | string | - | Description text below the label |
name | string | - | Name attribute for form submission |
value | string | - | Value attribute for form submission |
id | string | auto-generated | Unique identifier for the checkbox |
class | string | - | Additional CSS classes to apply |
Accessibility
The Checkbox component follows WCAG 2.1 AA guidelines:
Screen Reader Support
- Semantic HTML: Uses native
<input type="checkbox">for proper identification - Label Association: Proper
forattribute linking labels to inputs - Description Support: Uses
aria-describedbyfor additional context - State Announcement: Screen readers announce checked/unchecked states
- Required Indication: Both visual and semantic indication of required fields
Keyboard Navigation
- Space Key: Toggles the checkbox state
- Tab Navigation: Focuses the checkbox in tab order
- Focus Indicators: Clear visual focus rings for keyboard users
Visual Accessibility
- High Contrast: Meets WCAG contrast requirements in all color variants
- Touch Targets: Minimum 44x44px touch target size (large variant)
- Color Independence: State is indicated by shape/icon, not just color
- Motion Sensitivity: Smooth but not excessive transitions
State Communication
- Indeterminate State: Properly communicated to assistive technology
- Disabled State: Prevents interaction and announces disability
- Error States: Uses
aria-invalidfor validation feedback
Examples
Terms and Conditions
By checking this box, you acknowledge that you have read and agree to our terms of service.
Newsletter Subscription with Options
Multi-level Selection
Choose individual features below
Detailed reporting and insights
Share projects with team members
Use your own logos and colors
Error Validation
This action cannot be undone
Your email address has been confirmed
<!-- Basic Usage --><Checkbox label="Subscribe to newsletter" />
<!-- With Description --><Checkbox label="Enable notifications" description="Get alerts when new content is available"/>
<!-- Different States --><Checkbox checked label="Already selected" /><Checkbox indeterminate label="Partially selected" /><Checkbox disabled label="Cannot be changed" />
<!-- Intent Variants --><Checkbox intent="success" checked label="Completed task" /><Checkbox intent="danger" required label="Confirm deletion" />
<!-- Form Integration --><Checkbox name="preferences" value="email_notifications" label="Email notifications" required/>
<!-- Sizes --><Checkbox size="small" label="Compact checkbox" /><Checkbox size="large" label="Large touch target" />