When to Use
Use TreeGrid when hierarchical rows expand and each row also contains several
navigable columns, such as a file browser with size and modified-date columns.
Use Tree for one-column hierarchies and DataGrid when rows are flat rather
than parent and child nodes.
Features
The behavior Atom owns before your product adds appearance.
- Implements
role="treegrid" with row, row header, column header, and gridcell parts.
- Supports controlled and uncontrolled expansion.
- Supports controlled and uncontrolled active cell state.
- Supports optional row selection with selectable parent rows.
- Hides descendant rows when parent rows are collapsed.
- Supports RTL-aware cell navigation and tree expand/collapse keys through
dir and Direction.Provider.
- Moves an active descendant cell to its collapsed ancestor's tree-column cell
when controlled or uncontrolled expansion hides that descendant.
- Gives actionable column headers equivalent pointer and Enter activation.
- Keeps sorting, filtering, resizing, editing, and virtualization outside the primitive.
Import
Anatomy
API Reference
Root
Owns hierarchical visibility, active-cell navigation, optional row selection,
expansion, direction, and the single focus target for the entire grid.
children | ReactNode | - |
value | string | string[] | null | - |
defaultValue | string | string[] | null | depends on selectionMode |
onValueChange | (value) => void | - |
onKeyDown | (event) => void | - |
expandedValue | string[] | - |
defaultExpandedValue | string[] | [] |
onExpandedValueChange | (value: string[]) => void | - |
activeCell | { rowIndex: number; columnIndex: number } | null | - |
defaultActiveCell | { rowIndex: number; columnIndex: number } | null | null |
onActiveCellChange | (cell: TreeGridCellCoordinates | null) => void | - |
selectionMode | "none" | "single" | "multiple" | "none" |
disabled | boolean | false |
readOnly | boolean | false |
loop | boolean | false |
dir | "ltr" | "rtl" | Direction.Provider |
rowCount | number | - |
columnCount | number | - |
selectOnRowClick | boolean | false |
render | RenderProp | - |
asChild | boolean | false |
role | "treegrid" |
aria-activedescendant | Active cell id when a cell is active |
aria-colcount | columnCount or -1 |
aria-disabled | "true" when disabled |
aria-multiselectable | "true" when selectionMode="multiple" |
aria-readonly | "true" when read-only |
aria-rowcount | rowCount or -1 |
[data-slot] | "tree-grid" |
[data-active] | Present when a cell is active |
[data-focused] | Present while focus is inside the treegrid |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-column-count] | Normalized positive columnCount |
[data-row-count] | Normalized positive rowCount |
[data-selection-mode] | "single" or "multiple" |
Caption
Provides a visible accessible name or description for the treegrid.
children | ReactNode | - |
render | RenderProp | - |
asChild | boolean | false |
[data-slot] | "tree-grid-caption" |
Groups header Rows and ColumnHeader cells above the scrollable body.
children | ReactNode | - |
render | RenderProp | - |
asChild | boolean | false |
[data-slot] | "tree-grid-header" |
Row
Registers one hierarchical row, its parent, visibility, expansion, selection,
and normalized row index for all cells inside it.
rowIndex | number | - |
index | number | - |
value | string | required |
parentValue | string | null | null |
level | number | 1 |
expandable | boolean | false |
selectable | boolean | true |
disabled | boolean | false |
render | RenderProp | - |
asChild | boolean | false |
role | "row" |
aria-disabled | "true" when row or root is disabled |
aria-expanded | "true" or "false" when expandable |
aria-hidden | "true" when hidden by a collapsed parent row |
aria-level | Hierarchical level |
aria-rowindex | Normalized positive row index |
aria-selected | "true" or "false" when selection is enabled |
[data-slot] | "tree-grid-row" |
[data-expandable] | Present when expandable |
[data-selectable] | Present when selectable and selection is enabled |
[data-selection-disabled] | Present when not selectable and selection is enabled |
[data-expanded] | Present when expanded |
[data-hidden] | Present when hidden by a collapsed parent row |
[data-disabled] | Present when disabled |
[data-parent-value] | Parent row value |
[data-level] | Hierarchical level |
[data-row-index] | Normalized positive row index |
[data-selected] | Present when selected |
[data-value] | Row value |
ColumnHeader
Renders a navigable header cell, optional sort state, and the normalized column
coordinate used by Root navigation.
children | ReactNode | - |
columnIndex | number | - |
index | number | - |
disabled | boolean | false |
sortDirection | "ascending" | "descending" | "none" | "other" | - |
onAction | () => void | - |
scope | native scope | "col" |
render | RenderProp | - |
asChild | boolean | false |
role | "columnheader" |
aria-colindex | Normalized positive column index |
aria-disabled | "true" when column header, row, or root is disabled |
aria-selected | "true" or "false" when selection is enabled |
aria-sort | sortDirection value |
[data-slot] | "tree-grid-column-header" |
[data-active] | Present when active and treegrid-focused |
[data-disabled] | Present when disabled |
[data-column-index] | Normalized positive column index |
[data-selected] | Present when row is selected |
[data-sort] | "ascending" | "descending" | "none" | "other" |
[data-actionable] | Present when an enabled indexed header has onAction |
Body
Groups the visible hierarchical data Rows below Header.
children | ReactNode | - |
render | RenderProp | - |
asChild | boolean | false |
[data-slot] | "tree-grid-body" |
Renders the cell that names its Row. Clicking it focuses the cell and toggles
the row when expandable.
children | ReactNode | - |
columnIndex | number | - |
index | number | - |
disabled | boolean | false |
scope | native scope | "row" |
render | RenderProp | - |
asChild | boolean | false |
role | "rowheader" |
aria-colindex | Normalized positive column index |
aria-disabled | "true" when row header, row, or root is disabled |
aria-selected | "true" or "false" when selection is enabled |
[data-slot] | "tree-grid-row-header" |
[data-active] | Present when active and treegrid-focused |
[data-disabled] | Present when disabled |
[data-column-index] | Normalized positive column index |
[data-selected] | Present when row is selected |
Cell
Renders a navigable data cell and registers its normalized column coordinate
with the current Row.
children | ReactNode | - |
columnIndex | number | - |
index | number | - |
disabled | boolean | false |
render | RenderProp | - |
asChild | boolean | false |
role | "gridcell" |
aria-colindex | Normalized positive column index |
aria-disabled | "true" when cell, row, or root is disabled |
aria-selected | "true" or "false" when selection is enabled |
[data-slot] | "tree-grid-cell" |
[data-active] | Present when active and treegrid-focused |
[data-disabled] | Present when disabled |
[data-column-index] | Normalized positive column index |
[data-selected] | Present when row is selected |
Groups optional summary Rows after Body.
children | ReactNode | - |
render | RenderProp | - |
asChild | boolean | false |
[data-slot] | "tree-grid-footer" |
Advanced compound parts can use useTreeGridContext and
useTreeGridRowContext with their matching public providers.
Examples
Expandable Rows
Accessibility
TreeGrid follows the WAI-ARIA treegrid pattern
with Root focus and aria-activedescendant. Provide an accessible name with
Caption, aria-label, or aria-labelledby.
| Expand / next-cell arrow | Expands a collapsed expandable row, or moves to the next cell: ArrowRight in LTR, ArrowLeft in RTL |
| Collapse / previous-cell arrow | Collapses an expanded row, moves to parent, or moves to the previous cell: ArrowLeft in LTR, ArrowRight in RTL |
ArrowDown / ArrowUp | Moves between visible rows |
Home / End | Moves within a row |
Ctrl+Home / Ctrl+End | Moves to first or last visible cell |
Enter | Calls onAction for an actionable active ColumnHeader; otherwise toggles an expandable tree-column row or selects the active row. |
Space | Selects the active row when selection is enabled. |
Changelog
Unreleased
0.24.0
- Added source-led Agent Knowledge for hierarchical grid selection, indexed
relationships, expansion, active-cell focus, row selection, header actions,
and virtualization boundaries.
0.18.0
- Added
ColumnHeader.onAction with equivalent enabled pointer and active-cell
Enter activation.
- Relocate active state to a collapsed ancestor's tree-column cell when a
controlled or uncontrolled collapse hides the active descendant.
0.2.0
- Added
Direction.Provider and dir support to mirror TreeGrid horizontal
cell navigation and expand/collapse arrow behavior in RTL.
0.1.0