Menu

Tree view

Nested tree rows + tree. 3 levels × 3 states.

Installation

$ npx uix-ui@latest add tree-view

This copies the file into components/ui/tree-view.tsx in your project. npx shadcn@latest add @uix/tree-view works too.

Usage

tree-view.tsx
import { Tree, TreeItem } from "@/components/ui/tree-view";

<Tree style={{ width: 280, maxWidth: "100%" }} aria-label="Product files">
  <TreeItem expanded={open} onClick={() => setOpen(!open)}>teas</TreeItem>
  {open ? (
    <>
      <TreeItem level="2" selected={sel === "green.md"} onClick={() => setSel("green.md")}>sylhet-green.md</TreeItem>
      <TreeItem level="2" selected={sel === "chai.md"} onClick={() => setSel("chai.md")}>masala-chai.md</TreeItem>
    </>
  ) : null}
  <TreeItem selected={sel === "readme"} onClick={() => setSel("readme")}>README.md</TreeItem>
</Tree>

Props

PropTypeDefaultDescription
level1 | 2 | 3"1"
selectedbooleanfalse
expandedboolean–True / false for a folder (open / closed), left out for a file.

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
  • components/ui/icons.tsx
This file exports 2 parts: Tree, TreeItem. Use only the ones you need.
esc

↑↓ to navigate · ↵ to select · esc to close