Skip to Content
Notion UI

Tree

A collapsible tree for nested items such as folders and files.

Tree Default

const tree = useTree(folderNodes, {});
return (
  <Tree tree={tree}>
    <TreeList nodeIds={tree.entity.rootIds} />
  </Tree>
);

Installation

pnpm add @notion-kit/ui

Usage

useTree builds a tree from flat records with id and parentId fields.

Basic Example

import { Tree, useTree } from "@notion-kit/ui/tree";
import { TreeList } from "@notion-kit/ui/tree/presets";

const data = [
  { id: "1", parentId: null, title: "Folder 1" },
  { id: "1.a", parentId: "1", title: "File A" },
  { id: "2", parentId: null, title: "Folder 2" },
];

export default function MyTree() {
  const tree = useTree(data, {});

  return (
    <Tree tree={tree}>
      <TreeList nodeIds={tree.entity.rootIds} />
    </Tree>
  );
}

Examples


Non-Collapsible Tree

Disable collapsing to show all nodes expanded by default.

Tree Non Collapsible

useTree(data, { collapsible: false });

Multi-Select

Enable selection of multiple tree items.

Tree Multi Select

useTree(data, { selectionMode: "multiple" });

Show Empty Children

Display an indicator when a folder has no children.

Tree Show Empty

useTree(data, { showEmptyChild: true });

Combobox Tree

A searchable tree interface using a combobox.

Tree Combobox

<ComboboxTree tree={tree} />

API Reference

useTree

Creates a tree instance from flat data.

const tree = useTree<T>(data, options);

Parameters:

Prop

Type

TreeOptions:

Prop

Type

Returns: TreeInstance<T>

The tree instance exposes:

  • entity: The tree entity with rootIds, nodes, etc.
  • state: Current tree state (expanded, selected nodes)
  • expand(id): Expand/collapse a node
  • select(id): Select a node
  • getVisibleIds(): Get currently visible node IDs

Tree

Root container providing tree context.

Prop

Type

Tree.Item

A slottable tree item.

Tree.ExpandIndicator

A slottable button to expand/collapse a node.

Prop

Type

Tree.EmptyIndicator

A slottable indicator to show when a node has no children.

Tree.Group

A slottable tree group.

Tree.List

Renders tree nodes recursively.

Prop

Type

TreeList (Preset)

Pre-styled tree list component from @notion-kit/ui/tree/presets.

Prop

Type

ComboboxTree (Preset)

Searchable tree component with combobox behavior.

Prop

Type

type TreeItemData (Preset)

Base interface for tree item data.

interface TreeItemData {
  id: string;
  parentId: string | null;
  title: string;
  icon?: IconData;
  group?: string | null;
}

Architecture

The tree instance manages expansion and selection state. Use getVisibleIds() to read the nodes visible under the current expansion state.

On this page