npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-tree-view.json --yesTree view
ProNested rows a person opens and closes, to pick one (or several) of them, for React and Tailwind CSS. Part of Goop Pro.
What an agent sees
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' },
]}
/>
);
}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.
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-tree-view.json --yesAdd the Goop Tree view to this project. The install steps are at https://goop.so/docs/install.mdUsage
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
- Each option with its sentence: tree-view--options.md
- State: expanded (expanded / defaultExpanded / onExpandedChange); value (value / defaultValue / onValueChange)
- data-slot values (to select a part by): tree-view, tree-view-checkbox, tree-view-chevron, tree-view-icon, tree-view-indent, tree-view-item, tree-view-label, tree-view-loading, tree-view-meta, tree-view-open-icon, tree-view-toggle
TreeView: every option
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
hasChildrenrow with nochildrenopens; hand them back initems. - 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
| Key | What it does |
|---|---|
| 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
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| 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.
- How the theme moves, and how to move your own parts the same way: Motion.
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.