Components
Checkbox
A form control component that allows users to select one or multiple options. Built with accessibility and ease of use in mind, supporting both controlled and uncontrolled usage.
Props
label
: string (optional) - Text label displayed next to the checkboxclassName
: string (optional) - Additional CSS classes for the checkbox input- All standard HTML input[type=“checkbox”] attributes are supported
Usage Examples
Basic Checkbox
Controlled Checkbox
With Custom Styling
Disabled State
Required Field
Within a Form
Styling
The component uses Tailwind CSS for styling and includes:
- Custom checkbox design
- Focus states for keyboard navigation
- Hover effects
- Disabled state styling
- Dark mode support
- Customizable colors through className
Accessibility Features
- Proper label association using unique IDs
- Keyboard navigation support
- Screen reader friendly
- Focus visible states
- ARIA attributes when needed
Best Practices
-
Form Usage:
- Always provide clear, descriptive labels
- Group related checkboxes
- Indicate required fields
- Maintain consistent spacing
-
Interaction:
- Provide immediate visual feedback
- Ensure sufficient touch target size
- Keep labels concise but descriptive
-
Validation:
- Show clear error states
- Provide helpful error messages
- Validate on form submission
Implementation Notes
- Uses React’s forwardRef for ref forwarding
- Generates unique IDs for label association
- Maintains native checkbox behavior
- Supports form validation