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.
Composition
Section titled “Composition”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 rowsExamples
Section titled “Examples”Default expansion
Section titled “Default expansion”import { Table } from "@nesra/ui/table";import { TableTree, type TableTreeItem } from "@nesra/ui/table-tree";
const rows: TableTreeItem<{ owner: string }>[] = [ { id: "workspace", label: "Workspace", supportingText: "All projects", data: { owner: "Team" }, children: [ { id: "website", label: "Website", supportingText: "In progress", data: { owner: "Maya" }, children: [{ id: "design", label: "Design", data: { owner: "Rafi" } }], }, { id: "mobile", label: "Mobile", data: { owner: "Dina" } }, ], },];
export function TableTreeBasicExample() { return ( <div className="max-w-full overflow-x-auto"> <TableTree.Root defaultExpandedIds={["workspace"]}> <Table.Header> <Table.Row> <Table.Head className="min-w-60" scope="col"> Name </Table.Head> <Table.Head className="min-w-40" scope="col"> Owner </Table.Head> </Table.Row> </Table.Header> <TableTree.Body rows={rows} renderCells={(row) => <Table.Cell>{row.data.owner}</Table.Cell>} /> </TableTree.Root> </div> );}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.
Expanded hierarchy
Section titled “Expanded hierarchy”import { Info } from "lucide-react";import { Table } from "@nesra/ui/table";import { TableTree, type TableTreeItem } from "@nesra/ui/table-tree";
const rows: TableTreeItem<{ owner: string }>[] = [ { id: "product", label: "Product", supportingText: "All product work", labelAdornment: <Info aria-hidden="true" size={14} />, data: { owner: "Team" }, children: [ { id: "website", label: "Website", supportingText: "In progress", data: { owner: "Maya" }, children: [{ id: "navigation", label: "Navigation", data: { owner: "Rafi" } }], }, { id: "mobile", label: "Mobile", data: { owner: "Dina" } }, ], },];
export function TableTreeExpandedExample() { return ( <div className="max-w-full overflow-x-auto"> <TableTree.Root defaultExpandedIds={["product", "website"]}> <Table.Header> <Table.Row> <Table.Head className="min-w-60" scope="col"> Name </Table.Head> <Table.Head className="min-w-40" scope="col"> Owner </Table.Head> </Table.Row> </Table.Header> <TableTree.Body rows={rows} renderCells={(row) => <Table.Cell>{row.data.owner}</Table.Cell>} /> </TableTree.Root> </div> );}Account hierarchy with child headings
Section titled “Account hierarchy with child headings”import { Badge } from "@nesra/ui/badge";import { Table } from "@nesra/ui/table";import { TableTree, type TableTreeItem } from "@nesra/ui/table-tree";
type Account = { name: string; type: string; balance: string; active: boolean };
const accounts: TableTreeItem<Account>[] = [ { id: "1200", label: "1200", data: { name: "Bank", type: "Aset", balance: "Debit", active: true }, }, { id: "1110", label: "1110", data: { name: "Kas", type: "Aset", balance: "Debit", active: true }, children: [ { id: "11101", label: "11101", data: { name: "Kas Kecil", type: "Aset", balance: "Debit", active: true }, }, { id: "11102", label: "11102", data: { name: "Kas Besar", type: "Aset", balance: "Debit", active: true }, }, ], }, { id: "1510", label: "1510", data: { name: "Aset Dalam Penyelesaian", type: "Aset", balance: "Debit", active: true }, },];
const columns = ["Kode Akun", "Nama Akun", "Tipe Akun", "Saldo Normal", "Status"];
function AccountHeadings() { return ( <Table.Row> {columns.map((column) => ( <Table.Head key={column} scope="col"> {column} </Table.Head> ))} </Table.Row> );}
export function TableTreeAccountsExample() { return ( <div className="max-w-full overflow-x-auto"> <TableTree.Root defaultExpandedIds={["1110"]} className="min-w-[800px]" density="directory"> <caption className="sr-only">Chart of accounts</caption> <colgroup> <col className="w-[150px]" /> <col /> <col className="w-[170px]" /> <col className="w-[180px]" /> <col className="w-[140px]" /> </colgroup> <Table.Header> <AccountHeadings /> </Table.Header> <TableTree.Body rows={accounts} disclosurePosition="end" renderExpandedHeader={() => <AccountHeadings />} renderCells={(row) => ( <> <Table.Cell>{row.data.name}</Table.Cell> <Table.Cell>{row.data.type}</Table.Cell> <Table.Cell>{row.data.balance}</Table.Cell> <Table.Cell> <Badge color={row.data.active ? "success" : "neutral"} appearance="soft"> {row.data.active ? "Aktif" : "Tidak aktif"} </Badge> </Table.Cell> </> )} /> </TableTree.Root> </div> );}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.
Disabled disclosure
Section titled “Disabled disclosure”import { Table } from "@nesra/ui/table";import { TableTree, type TableTreeItem } from "@nesra/ui/table-tree";
const rows: TableTreeItem<{ status: string }>[] = [ { id: "active", label: "Active projects", data: { status: "Available" }, children: [{ id: "site", label: "Website", data: { status: "In progress" } }], }, { id: "archive", label: "Archive", supportingText: "Access restricted", disabled: true, data: { status: "Unavailable" }, children: [{ id: "legacy", label: "Legacy site", data: { status: "Archived" } }], },];
export function TableTreeDisabledExample() { return ( <div className="max-w-full overflow-x-auto"> <TableTree.Root> <Table.Header> <Table.Row> <Table.Head className="min-w-60" scope="col"> Name </Table.Head> <Table.Head className="min-w-40" scope="col"> Status </Table.Head> </Table.Row> </Table.Header> <TableTree.Body rows={rows} renderCells={(row) => <Table.Cell>{row.data.status}</Table.Cell>} /> </TableTree.Root> </div> );}Controlled expansion and selection
Section titled “Controlled expansion and selection”import { useState } from "react";import { Table } from "@nesra/ui/table";import { TableTree, type TableTreeItem } from "@nesra/ui/table-tree";
const rows: TableTreeItem<{ owner: string }>[] = [ { id: "workspace", label: "Workspace", data: { owner: "Team" }, children: [ { id: "website", label: "Website", data: { owner: "Maya" }, children: [{ id: "design", label: "Design", data: { owner: "Rafi" } }], }, { id: "mobile", label: "Mobile", data: { owner: "Dina" } }, ], },];
export function TableTreeControlledExample() { const [expandedIds, setExpandedIds] = useState<string[]>(["workspace"]); const [selectedIds, setSelectedIds] = useState<string[]>([]);
return ( <div className="max-w-full overflow-x-auto"> <TableTree.Root expandedIds={expandedIds} onExpandedIdsChange={setExpandedIds}> <Table.Header> <Table.Row> <Table.Head className="min-w-60" scope="col"> Name </Table.Head> <Table.Head className="min-w-40" scope="col"> Owner </Table.Head> <Table.Head scope="col">Select</Table.Head> </Table.Row> </Table.Header> <TableTree.Body rows={rows} isRowSelected={(row) => selectedIds.includes(row.id)} renderCells={(row) => ( <> <Table.Cell>{row.data.owner}</Table.Cell> <Table.CheckCell checked={selectedIds.includes(row.id)} label={`Select ${row.label}`} onCheckedChange={(checked) => setSelectedIds((current) => checked ? [...current, row.id] : current.filter((id) => id !== row.id), ) } /> </> )} /> </TableTree.Root> </div> );}Light and Dark
Section titled “Light and Dark”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).
Accessibility
Section titled “Accessibility”- 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.
API reference
Section titled “API reference”TableTree.Root
Section titled “TableTree.Root”| 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.
TableTree.Body
Section titled “TableTree.Body”| 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.