Checkbox

Checkboxes are the reliable workhorses of form inputs. They let users make multiple selections or toggle binary options with confidence.

Preview
Code

Installation

First, make sure you have the required dependencies:

npx @rajdevxd/aura-ui add checkbox
yarn @rajdevxd/aura-ui add checkbox
pnpm dlx @rajdevxd/aura-ui add checkbox
bunx --bun @rajdevxd/aura-ui add checkbox

Usage

Here's how to implement checkboxes in your forms:

import { Checkbox } from "@/components/ui/checkbox"

const MyForm = () => {
  const [preferences, setPreferences] = React.useState({
    newsletter: false,
    notifications: true
  })

  return (
    <div className="space-y-4">
      <div className="flex items-center space-x-2">
        <Checkbox
          checked={preferences.newsletter}
          onCheckedChange={(checked) =>
            setPreferences(prev => ({ ...prev, newsletter: checked }))
          }
        />
        <label>Subscribe to newsletter</label>
      </div>

      <div className="flex items-center space-x-2">
        <Checkbox
          checked={preferences.notifications}
          onCheckedChange={(checked) =>
            setPreferences(prev => ({ ...prev, notifications: checked }))
          }
        />
        <label>Enable notifications</label>
      </div>
    </div>
  )
}

Props

PropTypeRequiredDescription
checkedbooleanNoThe current checked state
onCheckedChange(checked: boolean) => voidNoCallback when checkbox state changes
classNamestringNoAdditional CSS classes for custom styling

Features

  • Controlled Component: Full control over checked state
  • Accessibility: Proper keyboard navigation and screen reader support
  • Custom Styling: Easy to customize appearance
  • Theme Integration: Adapts to your design system

Common Issues

  1. "Checkbox not responding!" - Make sure you're handling the onCheckedChange callback
  2. "State not updating!" - Remember to update your component's state in the callback
  3. "Styling not working!" - The component uses custom styling, check your CSS setup

Contributing

Checkboxes are fundamental to forms! Help us improve their accessibility and user experience.

Checkboxes - because sometimes you need more than just yes or no! ☑️