Tree view

A React component in Beamline's Navigation category, in the free sample.

Nested folders and records with the full tree keyboard model (arrows, Home/End, *, type to jump), depth guides, counts and animated opening.

Use it for

  • Nested hierarchies: files, folders, teams, categories.

Not for

Anatomy

  • tree (a size container)
  • row: chevron, icon, label, badge, actions (revealed)
  • depth guides
  • group

States

  • collapsed
  • expanded
  • focused
  • selected
  • disabled
  • narrow room (under 20rem each level indents less, so deep rows keep their names)

Keyboard

  • ↑ ↓ visible rows
  • Inline-end arrow opens/enters (Right in LTR, Left in RTL)
  • Inline-start arrow closes/returns to parent (Left in LTR, Right in RTL)
  • Home / End
  • * opens all siblings
  • type to jump
  • Enter / Space selects

Motion

Groups open and close by height over 200 ms; the chevron turns. The selected row's tint and rule are one plate that travels to the next row chosen (ui/lib/contour.ts); expanding or collapsing a branch places it without travel; a selected row inside a closed branch has no plate. A row press is acknowledged at once; row actions arrive while the row is pointed at, holds focus or is selected (.reveal), in room kept for them.

Props

PropTypeDefaultDescription
nodes{ id, label, icon?, badge?, disabled?, children? }[]—Nodes rendered in their supplied hierarchy. Required.
expandedIds / defaultExpandedIds / onExpandedChangestring[]—expandedIds: Legacy expanded node ids. Deprecated: Use expanded instead. defaultExpandedIds: Legacy initial expanded node ids. Deprecated: Use defaultExpanded instead. onExpandedChange: Reports expanded node ids after a toggle; no callback by default.
selectedId / defaultSelectedId / onSelectstring / (node) => void—selectedId: Legacy selected node id. Deprecated: Use selected instead. defaultSelectedId: Legacy initial selected node id. Deprecated: Use defaultSelected instead. onSelect: Called when an item is activated; no handler by default.
aria-labelstring—The tree's name, e.g. "Project files".
classNamestyped part classes—Classes for the named visual parts; no part overrides by default.
styleCSSProperties—Inline styles on the documented visual root; no inline overrides by default.
refHTMLUListElement—Receives the list root; no ref by default.
actions(node) => ReactNode—Small actions at the end of a row (rename, add, more): they arrive while the row is pointed at, holds focus or is selected, take no room from the label when they appear (the room is kept), and always show on touch. Tab moves from the active row to its actions.
expandedstring[]—Controlled expanded node ids; omitted by default to keep expansion locally.
defaultExpandedstring[]—Initially expanded node ids; defaults to an empty list.
expandedIdsstring[]—Legacy expanded node ids. Deprecated: Use expanded instead.
defaultExpandedIdsstring[]—Legacy initial expanded node ids. Deprecated: Use defaultExpanded instead.
onExpandedChange((expandedIds: string[]) => void)—Reports expanded node ids after a toggle; no callback by default.
selectedstring | null—Controlled selected node id; null clears selection, and omission keeps it locally.
defaultSelectedstring | null—Initial selected node id; defaults to null.
onSelectedChange((id: string | null) => void)—Reports the selected node id after activation; no callback by default.
selectedIdstring | null—Legacy selected node id. Deprecated: Use selected instead.
defaultSelectedIdstring | null—Legacy initial selected node id. Deprecated: Use defaultSelected instead.
onSelect((node: TreeNode) => void)—Called when an item is activated; no handler by default.
classNamestring—Classes on the documented visual root; no override by default.
dir"ltr" | "rtl"—Reading direction; inherits the surrounding direction when omitted. Defaults to the surrounding reading direction.
loadChildren((node: TreeNode) => Promise<TreeNode[]>)—Loads a node's children the first time it opens (nodes with `hasChildren` and no `children`): a loading row shows while it runs, a failure is said in place with Try again (→ on the row tries again too), and the children are kept after that. Reject with an Error whose message says why.
fields((level: number) => TreeField[])—The values each level shows beside its nodes' names (level 1 is the top), from each node's `fields`.

Built from

Used in

Dependencies

lucide-react

Import

import { TreeView } from "@beamline/tree-view";

Get it

Tree view is part of Beamline UI. Install the parts you need in your React app as compiled packages or editable source. Tree view is included in the free MIT sample. Get Beamline · Connect your agent

More in Navigation

  • Sidebar: The app's main navigation: sections, items with counts and one level of sub-pages, an icon rail with tooltips (⌘B, the trigger or the edge), and a sheet…
  • Stepper: Where someone is in a multi-step flow: done steps carry a check, the current one a ring, and the line between marks fills as steps complete.
  • Table of contents: The sections of a long page beside it, with the one being read marked as you scroll: the marker travels down the rail between sections, the rail fills…
  • Tabs: Switches between panels of one object; one indicator slides to the active tab, counts sit beside labels, and the tabs a row has no room for fold into More.
  • Navigation menu: A site or docs header whose sections open into one panel that resizes and slides between them; NavigationMenuCard is the standard link row.
  • Menu bar: A desktop-style File / Edit / View bar for editor-like apps; each menu takes the same rows as the dropdown menu, and pointing moves between open menus.
  • Pagination: Moves through pages of a known length: first, last and the current page's neighbours, with an optional “41–60 of 468”. It answers to its own room…
  • User menu: The account menu behind the avatar: who is signed in, status, theme, account pages and sign out with progress; a bottom sheet on phones.
  • Breadcrumb: Where a page sits and the way back up; it shows as many levels as its room holds and folds the ones nearest the top into a menu.

Compared in: MUI alternatives for React apps

Part of Beamline UI: polished, editable React components and complete screens for custom applications. Build your own style from any look; tokens, fonts, radii, motion; not only colours.