Skip to content
Haze UI

Checkbox Tree

Nested checkboxes with expandable groups. A parent shows checked, unchecked or mixed from its descendants and sets them all.

pnpm dlx shadcn@latest add @haze/checkbox-tree
Open preview in a new tab
Livesmall script

When to use

  • Permissions, scopes or categories that come in groups with sub-options.
  • Choosing a subset of a hierarchy, for example folders to sync.

When not to use

  • A flat list; use checkbox.
  • Browsing items that are opened rather than selected; use file-tree.

Installation

Add the Haze registry to components.json once, then install Checkbox Tree with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/checkbox-tree
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique ID for the tree; input IDs derive from it.
labelstringPermissionsAccessible name of the group.
namestringidForm field name shared by the leaf checkboxes, whose value is the item id. Parents are not submitted.
items{ id, label, checked?, disabled?, expanded?, children? }[]–The tree, to any depth. A demo permissions tree is used when omitted. Leaves hold the checked state; a parent starts checked when all its enabled leaves are.
classstring–Classes on the wrapper.

Keyboard interactions

TabShiftTab
Move between checkboxes and group toggles.
Space
Toggle the focused checkbox.
Arrow DownArrow Up
Move to the next or previous visible checkbox.
Arrow RightArrow Left
Open a group or enter it; close a group or move to its parent.
HomeEnd
First or last visible checkbox.

Accessibility

  • Every box is a native checkbox. A parent in the mixed state uses the native indeterminate property, which is exposed as mixed, and shows a minus.
  • Toggles are buttons with aria-expanded and aria-controls and appear once scripts run; without scripts every group stays open and leaf checkboxes still submit.
  • Disabled leaves keep their state and are skipped when a parent is toggled and when its state is worked out.
  • A tree-change event bubbles with the list of checked leaf values.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Checkbox Tree" with `npx shadcn@latest add @haze/checkbox-tree`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import CheckboxTree from "@/components/haze/ui/checkbox-tree.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/checkbox-tree.md

  • Customize with real content

    Adapt the Haze checkbox-tree ui for our product. Replace the demo values of these props with our real content: id, label, name, items, class. Keep the layout, the heading level rules and these accessibility details: Every box is a native checkbox. A parent in the mixed state uses the native indeterminate property, which is exposed as mixed, and shows a minus. Toggles are buttons with aria-expanded and aria-controls and appear once scripts run; without scripts every group stays open and leaf checkboxes still submit. Disabled leaves keep their state and are skipped when a parent is toggled and when its state is worked out. A tree-change event bubbles with the list of checked leaf values. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using checkbox-tree, check it fits: use it when permissions, scopes or categories that come in groups with sub-options.; choosing a subset of a hierarchy, for example folders to sync.. Avoid it when a flat list; use checkbox.; browsing items that are opened rather than selected; use file-tree.. Alternatives: @haze/checkbox, @haze/file-tree, @haze/tree-table.

Dependencies

  • npm: @lucide/astro
  • @haze/checkbox-tree
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog