Skip to content
Corsair UI
Browse the docs

ComponentsNo. 13 of 109

Checkbox

Checkbox with checked, unchecked and indeterminate states.

Installation

pnpm dlx shadcn@latest add @corsair-ui/checkbox

No setup needed: the CLI finds @corsair-ui in the shadcn registry directory. The files land in your project as source: edit them like your own code. More in Installation.

Also adds
utils
npm
@radix-ui/react-checkboxclsxlucide-reacttailwind-merge

Examples

Default

States

Select all

Indeterminate while some are selected.

API

Built on Radix Checkbox; every prop it takes is passed through.

Accessibility

  • Space toggles it; checked="indeterminate" is announced as mixed.
  • The mark animates only when motion is allowed.

Compatibility

Tailwind CSS
3.4 and 4, both checked in CI
React
19
Rendering
Client component ("use client")

Source

1 file, installed as source you own
checkbox.tsxView on GitHub
"use client";

import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { CheckIcon, MinusIcon } from "lucide-react";
import type { ComponentProps } from "react";

import { cn } from "@/registry/default/lib/utils";

/** Pass `checked="indeterminate"` for a partially selected group. Pair it with a Label. */
function Checkbox({ className, ...props }: ComponentProps<typeof CheckboxPrimitive.Root>) {
  return (
    <CheckboxPrimitive.Root
      data-slot="checkbox"
      className={cn(
        "peer group border-input bg-field text-primary-foreground size-4 shrink-0 cursor-pointer rounded-[4px] border",
        "transition-[color,background-color,border-color,box-shadow] outline-none motion-reduce:transition-none",
        "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
        "aria-[invalid=true]:border-destructive aria-[invalid=true]:ring-destructive/20",
        "data-[state=checked]:border-primary data-[state=checked]:bg-primary",
        "data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      {...props}
    >
      {/* The mark scales in while the box fills, and back out when cleared. */}
      <CheckboxPrimitive.Indicator
        data-slot="checkbox-indicator"
        className={cn(
          "flex items-center justify-center text-current",
          "zoom-in-50 fade-in-0 zoom-out-50 fade-out-0 ease-out",
          "motion-safe:data-[state=checked]:animate-in motion-safe:data-[state=indeterminate]:animate-in motion-safe:data-[state=unchecked]:animate-out"
        )}
      >
        <CheckIcon className="size-3.5 group-data-[state=indeterminate]:hidden" />
        <MinusIcon className="hidden size-3.5 group-data-[state=indeterminate]:block" />
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  );
}

export { Checkbox };