HextaUI

Checkbox: Select all

Inside a <CheckboxGroup />, a checkbox with parent ticks every value in allValues. It turns indeterminate when only some are ticked.

"use client"

import * as React from "react"

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

const fruits = ["Apple", "Banana", "Cherry", "Mango", "Peach"]

export function CheckboxSelectAll() {
  const [value, setValue] = React.useState<string[]>(["Banana"])

  return (
    <div className="text-sm">
      <CheckboxGroup
        aria-label="Fruits"
        value={value}
        onValueChange={setValue}
        allValues={fruits}
      >
        <label className="flex items-center gap-3">
          <Checkbox parent />
          <span>
            Select all{" "}
            <span className="text-muted-foreground">
              ({value.length}/{fruits.length})
            </span>
          </span>
        </label>
        <div className="flex flex-col gap-3 ps-7">
          {fruits.map((fruit) => (
            <label key={fruit} className="flex items-center gap-3">
              <Checkbox value={fruit} />
              {fruit}
            </label>
          ))}
        </div>
      </CheckboxGroup>
    </div>
  )
}

This adds the example as components/examples/checkbox/select-all.tsx, together with the Checkbox component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/checkbox-select-all.json

To add only the component, follow the Checkbox installation.

Props in this example

The Checkbox props this example sets, from the API reference.

PropTypeDefault
valueIdentifies the box inside a group and is what the form submits. Falls back to name, then “on”.
string–
parentControls every value in the group’s allValues. Only inside a CheckboxGroup.
booleanfalse
PropTypeDefault
valueValues of the ticked checkboxes.
string[]–
onValueChange
(value: string[], details) => void–
allValuesEvery value in the group. Required for a parent checkbox.
string[]–

Every prop is in the Checkbox API reference.

See them all, with keyboard support and accessibility notes, on the Checkbox page.