# Tree view

A keyboard-navigable hierarchy with controlled expansion, selection and optional native actions.

Access: pro. Category: Navigation. Kind: composite.

## When to use

- Use it when a page needs a keyboard-navigable hierarchy with controlled expansion, selection and optional native actions.
- Choose it as the nav region when composing a page from independently reusable TidalUI sections.

## Alternatives

- Choose navigation-bar instead when responsive saas navigation with native links, actions and an in-flow mobile disclosure is the actual interface need, rather than tree view.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Tree view

```sh
npx shadcn@latest add @tidal-pro/tree-view
```

Stylesheets: `components/ui/tidal.css`, `components/ui/tree-view.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/tree-view.css";
import{TidalTreeView}from"./components/ui/tree-view";
export default()=><div className="tidal-scope"><TidalTreeView expandedIds={["example"]} label={"Demo"} nodes={[{id:"example",label:"Demo",textValue:"Demo"}]} onExpandedChange={() => {}} onSelectedChange={() => {}} selectedId={"example"}/></div>;
```

## Structured props

- `TidalTreeView.expandedIds: ReadonlyArray<string>`: Required expanded ids value accepted by this exported component.
- `TidalTreeView.label: string`: Required label value accepted by this exported component.
- `TidalTreeView.nodes: ReadonlyArray<TidalTreeNode>`: Required nodes value accepted by this exported component.
- `TidalTreeView.onExpandedChange: (expandedIds: readonly string[], node: TidalTreeNode, event: TidalTreeInteractionEvent | ReactMouseEvent<HTMLButtonElement>) => void`: Callback invoked when the expanded change interaction is proposed.
- `TidalTreeView.onSelectedChange: (selectedId: string, node: TidalTreeNode, event: TidalTreeInteractionEvent) => void`: Callback invoked when the selected change interaction is proposed.
- `TidalTreeView.selectedId: string | null`: Required selected id value accepted by this exported component.
- `TidalTreeView.dir?: "ltr" | "rtl" | undefined` (default "ltr"): Optional dir value accepted by this exported component.
- `TidalTreeView.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalTreeView.emptyMessage?: ReactNode` (default "No items available."): Optional empty message value accepted by this exported component.
- `TidalTreeView.labels?: Partial<TidalTreeViewLabels> | undefined`: Optional labels value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/tree-view.tsx) | [Manifest](https://tidalui.com/examples/tree-view.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useMemo, useState } from "react";

import { TidalTreeView, type TidalTreeNode } from "./components/ui/tree-view";

import "./components/ui/tree-view.css";



const tidalExampleStyles = ".tree-demo {\n  display: grid;\n  width: 100%;\n  max-width: 620px;\n  min-width: 0;\n  gap: 12px;\n}\n\n.tree-demo-detail {\n  display: grid;\n  min-width: 0;\n  gap: 3px;\n  border: 1px solid var(--t-border);\n  border-radius: 14px;\n  padding: 12px 14px;\n  background: var(--t-subtle);\n}\n\n.tree-demo-detail > span,\n.tree-demo-note {\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n}\n\n.tree-demo-detail strong {\n  min-width: 0;\n  font-size: 13px;\n  line-height: 1.35;\n  overflow-wrap: anywhere;\n}\n\n.tree-demo-detail p,\n.tree-demo-note {\n  margin: 0;\n  overflow-wrap: anywhere;\n}\n\n.tree-demo-detail p {\n  font-size: 12px;\n  line-height: 1.45;\n}\n\n.tree-demo-note {\n  padding-inline: 4px;\n}\n\n@media (max-width: 390px) {\n  .tree-demo {\n    gap: 10px;\n  }\n\n  .tree-demo-detail {\n    padding: 10px 12px;\n  }\n}";

function FolderIcon() {
  return (
    <svg viewBox="0 0 20 20" fill="none" aria-hidden="true">
      <path
        d="M2.75 5.75c0-.83.67-1.5 1.5-1.5h3.1l1.4 1.5h7c.83 0 1.5.67 1.5 1.5v7c0 .83-.67 1.5-1.5 1.5H4.25c-.83 0-1.5-.67-1.5-1.5v-8.5Z"
        stroke="currentColor"
        strokeWidth="1.4"
      />
    </svg>
  );
}

function FileIcon() {
  return (
    <svg viewBox="0 0 20 20" fill="none" aria-hidden="true">
      <path
        d="M5 2.75h6l4 4v10.5H5V2.75Z"
        stroke="currentColor"
        strokeLinejoin="round"
        strokeWidth="1.4"
      />
      <path d="M11 2.75v4h4" stroke="currentColor" strokeWidth="1.4" />
    </svg>
  );
}

export function TreeViewDemo() {
  const [expandedIds, setExpandedIds] = useState<readonly string[]>([
    "product",
    "research",
  ]);
  const [selectedId, setSelectedId] = useState<string | null>("launch");
  const [status, setStatus] = useState("Launch checklist selected.");

  const nodes = useMemo<readonly TidalTreeNode[]>(
    () => [
      {
        id: "product",
        label: "Product",
        textValue: "Product",
        description: "Planning and release work",
        icon: <FolderIcon />,
        children: [
          {
            id: "roadmap",
            label: "Roadmap",
            textValue: "Roadmap",
            description: "Quarterly priorities",
            icon: <FileIcon />,
          },
          {
            id: "launch",
            label: "Launch checklist",
            textValue: "Launch checklist",
            description: "12 of 16 items complete",
            icon: <FileIcon />,
          },
        ],
      },
      {
        id: "research",
        label: "Research",
        textValue: "Research",
        description: "Notes from recent interviews",
        icon: <FolderIcon />,
        children: [
          {
            id: "interviews",
            label: "Interview notes",
            textValue: "Interview notes",
            description: "Six fictional local entries",
            icon: <FileIcon />,
          },
          {
            id: "themes",
            label: "Themes",
            textValue: "Themes",
            description: "Grouped observations",
            icon: <FileIcon />,
          },
        ],
      },
      {
        id: "archive",
        label: "Archive",
        textValue: "Archive",
        description: "Older sample material",
        icon: <FolderIcon />,
        lazyState: "Archived items are not included in this local sample.",
      },
    ],
    [],
  );

  const selectedNode = useMemo(() => {
    const queue = [...nodes];
    while (queue.length) {
      const node = queue.shift();
      if (!node) continue;
      if (node.id === selectedId) return node;
      if (node.children) queue.push(...node.children);
    }
    return null;
  }, [nodes, selectedId]);

  return (
    <section className="tree-demo" aria-label="Tree view sample">
      <TidalTreeView
        label="Project resources"
        nodes={nodes}
        expandedIds={expandedIds}
        selectedId={selectedId}
        onExpandedChange={(nextIds) => setExpandedIds(nextIds)}
        onSelectedChange={(nextId, node) => {
          setSelectedId(nextId);
          setStatus(`${node.textValue} selected.`);
        }}
      />

      <div
        className="tree-demo-detail"
        role="region"
        aria-label="Selected resource"
      >
        <span>Selected resource</span>
        <strong>{selectedNode?.label ?? "Nothing selected"}</strong>
        <p>{status}</p>
      </div>

      <p className="tree-demo-note">
        This sample changes local selection and expansion only.
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <TreeViewDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

label names the tree. nodes supplies unique string IDs, ReactNode labels/descriptions/icons, required plain textValue strings for typeahead, optional nested children, lazyState content, disabled state, native treeitem props/ref, disclosure props/ref, and optional native action button props/ref/callback. A disabled branch disables its visible descendants. expandedIds/onExpandedChange and selectedId/onSelectedChange are consumer-controlled. Arrow Up/Down, Home/End, logical Arrow Left/Right, Enter/Space and buffered typeahead operate the enabled visible treeitems; caller prevention and IME composition run before owned key behavior. Optional action buttons remain ordinary native Tab stops. labels localizes disclosure names. emptyMessage accepts ReactNode including numeric zero. dir controls logical RTL arrows and layout. disabled makes the whole tree inoperable and exposes its disabled state. The forwarded ref and remaining native attributes target the tree root. Consumers own data loading, expansion acceptance, selection results and action effects.
