---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Tree view

Nested rows a person opens and closes, to pick one (or several) of them, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `TreeView`.

## Try it

Open a team by its chevron or the arrow keys and choose a project; Support’s projects load when it opens; the line under the tree says what is chosen and, once you open or close one, which teams are open. Turn on Tick several to tick projects and whole teams.

The teams and projects are our own sample rows; Support’s rows come after a short wait of ours, nothing is fetched.

## When to use

- Nested rows a person opens and closes, to pick one (or several) of them.
- Also called: tree or file tree.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Tree view on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-tree-view.json --yes
```

```text
Add the Goop Tree view to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { TreeView } from '@/components/ui/goop/tree-view';
import { useState } from 'react';

function ProjectTree() {
  const [chosen, setChosen] = useState('transcript-search');
  return (
    <TreeView
      aria-label="Projects"
      value={chosen}
      onValueChange={setChosen}
      defaultExpanded={['research']}
      items={[
        {
          id: 'research',
          label: 'Research',
          icon: 'users',
          meta: '2',
          children: [
            { id: 'transcript-search', label: 'Transcript search', icon: 'box' },
            { id: 'study-templates', label: 'Study templates', icon: 'box' },
          ],
        },
        { id: 'data-retention', label: 'Data retention settings', icon: 'box' },
      ]}
    />
  );
}
```

- Fits: list (its recipe); list: collection (depth: nested).
- Also known as: Tree, FileTree, FolderTree, NestedList, TreeList.
- Keys: Up and Down move, Right opens a row or enters it, Left closes it or goes to its parent, Home and End, a typed letter finds a row, `*` opens every row beside the focused one; one tab stop. In a sidebar, set it under a SidebarGroup's label; a list of pages a person goes to is SidebarMenuButton rows, not a tree.
- height, width, padding, corner, border, background, text, motion: add no class for these.

## API reference

### TreeView: every option

```tsx
import { TreeView } from '@/components/ui/goop/tree-view';
```

### Options

- items: readonly TreeViewItem[] — The rows, each with its own rows under it.
- expanded?: readonly string[] — The open rows' ids, held by the caller.
- defaultExpanded?: readonly string[] = [] — The rows open at first, when the tree holds them.
- onExpandedChange?: (expanded: readonly string[]) => void — Called with the open rows' ids when a row opens or closes.
- onLoadChildren?: (id: string) => void — Asked for a row's rows when a `hasChildren` row with no `children` opens; hand them back in `items`.
- guides?: boolean = false — A hairline down each level, under its parent row's chevron.
- loadingLabel?: string = 'Loading' — The loading row's words, the caller's to translate.
- type?: 'single' | 'multiple' = 'single' — One row is chosen. Or: Rows are ticked with checkboxes, a parent mixed while only some are.
- value?: string | string[] — The chosen row's id ('' for none), held by the caller. Or: The ticked rows' ids, held by the caller.
- defaultValue?: string | string[] — The row chosen at first, when the tree holds it. Or: The rows ticked at first, when the tree holds them.
- onValueChange?: ((value: string) => void) | ((value: string[]) => void) — Called with the chosen row's id when a person chooses. Or: Called with the ticked rows' ids when a person ticks or unticks one.
- aria-label?: string — The tree's name, said by a reader ("Projects"); or name it with `aria-labelledby`.
- aria-labelledby?: string — The id of the element whose words name the tree (a heading above it).
- State: expanded (expanded / defaultExpanded / onExpandedChange); value (value / defaultValue / onValueChange)

## Keyboard

- Tab: move into the tree onto its chosen row (else its first), then out of it
- ArrowDown / ArrowUp: move to the next or the previous shown row
- ArrowRight: open a shut row, or move into an open row's first row
- ArrowLeft: shut an open row, or move to the row's parent
- Home / End: move to the first or the last shown row
- Enter / Space: choose the focused row (tick or untick it with several chosen)
- *: open every row beside the focused one
- a letter: move to the next row whose words start with the letters typed

## Accessibility

- The part itself answers the keys above.
- hover, focus-visible: the browser's own (:hover, :focus-visible): write nothing
- selected: the attribute aria-selected
- expanded: the attribute aria-expanded
- open: the attribute aria-expanded
- disabled: the attribute aria-disabled

## Motion

- The part sets its own motion: add no transition or animation of your own.

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Filter chips](/themes/trail/components/filter-chips): The row of filters applied to a list, under its filter controls.
- [Steps](/themes/trail/components/steps): A strip that shows which step of a flow the user is on, for display only.
- [Navigation menu](/themes/trail/components/navigation-menu): A site's header menu: a row of links and triggers, each trigger opening a panel of links.
- [Contents nav](/themes/trail/components/contents-nav): A table of contents for a long reading page (an article, a guide, a help page), each link jumping to a section.
