Skip to content

Table Tree

⋯

Table Tree renders Figma’s tree cell at indent levels 0–2 inside the native Table family. Its first cell contains a disclosure button and optional supporting text.

import { Table } from "@nesra/ui/table";
import { TableTree } from "@nesra/ui/table-tree";
const rows = [
{
id: "project",
label: "Project",
data: { owner: "Maya" },
children: [{ id: "design", label: "Design", data: { owner: "Ari" } }],
},
];
export function ProjectOwners() {
return (
<TableTree.Root defaultExpandedIds={["project"]}>
<caption>Project owners</caption>
<Table.Header>
<Table.Row>
<Table.Head>Work</Table.Head>
<Table.Head>Owner</Table.Head>
</Table.Row>
</Table.Header>
<TableTree.Body
rows={rows}
renderCells={(row) => <Table.Cell>{row.data.owner}</Table.Cell>}
/>
</TableTree.Root>
);
}

Both Table and TableTree are also exported from @nesra/ui.

TableTree.Root
├── Table.Header
│ └── Table.Row with Table.Head cells
└── TableTree.Body (rows and renderCells)
├── Table.Row with hierarchy cell and consumer cells
└── optional expanded header row before child rows
NameOwner
Level 1. WorkspaceAll projects
Team
Level 2, child of Workspace. WebsiteIn progress
Maya
Level 2, child of Workspace. Mobile
Dina

TableTree.Root renders the native table. TableTree.Body renders each visible row with Table.Row and Table.Cell. Use Table.Head for headers and return Table.Cell or ordinary <td> elements from renderCells. Wrap the table in an overflow-x-auto container when its columns exceed the available width.

NameOwner
Level 1. ProductAll product work
Team
Level 2, child of Product. WebsiteIn progress
Maya
Level 3, child of Website. Navigation
Rafi
Level 2, child of Product. Mobile
Dina
Chart of accounts
Kode AkunNama AkunTipe AkunSaldo NormalStatus
Level 1. 1200
BankAsetDebitAktif
Level 1. 1110
KasAsetDebitAktif
Kode AkunNama AkunTipe AkunSaldo NormalStatus
Level 2, child of 1110. 11101
Kas KecilAsetDebitAktif
Level 2, child of 1110. 11102
Kas BesarAsetDebitAktif
Level 1. 1510
Aset Dalam PenyelesaianAsetDebitAktif

renderExpandedHeader inserts a consumer-supplied table row between an expanded parent and its children. Return Table.Row with one Table.Head per column. disclosurePosition="end" places a plain up or down chevron after the hierarchy label, matching the account-code cell in the design. Column widths, sorting, cell content, and status badges remain consumer-owned.

NameStatus
Level 1. Active projects
Available
Level 1. ArchiveAccess restricted
Unavailable
NameOwnerSelect
Level 1. Workspace
Team
Level 2, child of Workspace. Website
Maya
Level 2, child of Workspace. Mobile
Dina

Table tree uses the Table roles and follows the page theme through .dark or data-theme="dark". The disclosure chevron uses Figma’s Icon/icon-muted (--nesra-icon-muted), gray-500 in Light and gray-400 in Dark. A disabled chevron uses --nesra-icon-disabled. The chevron button shows Box Shadow/Focus ring (shadow-nesra-focus-ring) on keyboard focus. Supporting text uses Text/text-support (--nesra-text-support).

  • The native table preserves column headers and reading order. Visible child rows follow their parent. Collapsed descendants are removed from the DOM.
  • A child heading row appears only while its parent is expanded. Give each heading a native scope="col" and keep the same column count as the table.
  • The chevron is a button with an expanded state. Tab reaches each visible disclosure and other interactive cell content in document order. Enter and Space activate the focused button. Arrow keys retain their normal browser behavior.
  • The first cell includes a screen-reader-only level and parent label. The disclosure button names its row and level. Use unique, stable row IDs and meaningful labels.
  • When selection is needed, the consuming table supplies its own selection cells and state. Table Tree does not select rows when focus moves or expansion changes.
  • Use a plain table for data without expandable rows. Use a separate tree for hierarchy without tabular columns. A treegrid is a distinct interaction pattern that requires managed arrow-key navigation across rows and cells.
Prop Type Default Effect
expandedIds readonly string[] — Controls expanded row IDs.
defaultExpandedIds readonly string[] [] Initial expanded IDs when uncontrolled.
onExpandedIdsChange (ids: string[]) => void — Receives the complete next set after a disclosure action.
children ReactNode — Table header and TableTree.Body composition.

TableTree.Root forwards a table ref and inherits Table props, including layout, className, and native table attributes.

Prop Type Default Effect
rows readonly TableTreeItem<T>[] — Consumer-owned hierarchy and row data.
renderCells (row, level) => ReactNode — Returns additional native cells. Level starts at 0.
renderExpandedHeader (row, level) => ReactNode — Returns a native header row before visible children of each expanded branch.
disclosurePosition "start" | "end" "start" Moves the disclosure after the label and uses a plain chevron when "end".
isRowSelected (row) => boolean — Applies consumer-owned selected-row presentation.

TableTree.Body forwards a tbody ref and inherits native <tbody> attributes, including className. isRowSelected changes only visual presentation. Applications own selection controls and state.

TableTreeItem<T> requires id, label, and data. Optional supportingText, labelAdornment, children, and disabled describe the first cell and expansion. Use labelAdornment for a consumer-supplied information icon or other label-adjacent content. disabled prevents expansion changes on a branch. Leaf rows have no disclosure button. IDs must be unique throughout the hierarchy. Expanded child state is retained when an ancestor closes and reopens.

Indent increases by 32px per level with the default disclosure and 28px with disclosurePosition="end". Levels 0–2 match the Figma set. Deeper levels continue the same progression without a cap. The cell uses the approved color, typography, and layout tokens.