Repository navigation
[tree] Add Tree and TreeGrid components - #6212
Open
flaviendelangle wants to merge 92 commits into
Open
flaviendelangle wants to merge 92 commits into
flaviendelangle wants to merge 92 commits into
Conversation
Ports the Tree from mui/base-ui-plus#4. Being in the same package as the internals it builds on lets it drop the pieces Plus needed to work from the outside: - Base UI's `useInitialLiveRegionTextMutation`, `DEFAULT_FIELD_ROOT_CONTEXT`, `warn` and `error` replace the Plus copies. - The composed-tree helpers of `tabbable.ts` replace the Tree's copies. - The built-in labels and status messages are English, like Toast's, and `aria-label` or the status `children` function translate them, as Base UI has no localization provider. - The CSS Modules demos inline their colors, and the demo color lint rule accepts system colors in forced colors mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size
PerformanceNo regressions in 36 benchmarks · precise to ±8.8% (±14.6% at worst) · ran 3m 12s · details Check out the code infra dashboard for more information about this PR. |
`stripInternal` removed `InternalTreeItemCollection` while other declarations still referenced it, which broke the public types check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flaviendelangle
marked this pull request as ready for review
November 10, 2026 15:36
flaviendelangle
requested review from
aarongarciah,
atomiks,
colmtuite,
jjenzz and
michaldudak
as code owners
November 10, 2026 15:36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tree now follows the tree view pattern by default: the list is a `tree` and each item a `treeitem`, read as one element. `Tree.GridProvider` opts into the treegrid pattern for items that hold controls the keyboard reaches. It installs the grid plugin, which owns the control registry and the in-row navigation moved out of the interaction plugin, so plain trees don't bundle it. - `Tree.ItemContent`, `Tree.ItemButton`, `Tree.ItemInput`, `Tree.ItemLink` and `Tree.ItemControl` throw outside the provider. - Outside a grid, `Tree.ItemCheckbox` stays out of the tab sequence and returns focus to its item, including after a label click. - Docs demos use plain trees, except item controls and links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tree and the tree whose items hold controls follow different accessibility patterns and need different markup, so each is its own component, built on the same store and plugins. - `Tree` follows the tree view pattern. `Tree.CheckboxItem` (with `Tree.CheckboxItemIndicator`) is an item that toggles like a checkbox and reports `aria-checked`, and `Tree.LinkItem` is an item rendered as a link, as in the APG navigation tree view. - `ActionTree` follows the treegrid pattern with one cell per item. Its root installs the grid navigation, and the cell and control parts move from `Tree` to `ActionTree.ItemContent`, `ItemCheckbox`, `ItemCheckboxIndicator`, `ItemButton`, `ItemInput`, `ItemLink` and `ItemControl`. It's not called TreeGrid, a name other libraries use for multi-column tree tables. - `Tree.GridProvider` is removed. A part of one component throws in the other's root, naming the part to use instead. - The Tree docs cover the plain tree, and a new Action Tree page covers controls inside items, each with its own demos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An `aria-label` on the cell left out the visible text of the controls inside it, which fails label in name (WCAG 2.5.3): axe reported `label-content-name-mismatch` for a cell holding a "Delete" button. The row keeps its name, as in the APG treegrid example and React Aria. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tree inside its own scroll container scrolled only that container to the focused row. When the container ran past the window, arrow keys moved focus to rows below the fold. While the row has focus, also reveal it in every scroller around the container, up to the page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A trigger rendered in a Tree.LinkItem sits inside the anchor, so a click expanded the item and also followed the link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItemControl ignored a disabled item or tree. A rendered Switch still toggled while the row told assistive tech it was disabled. ItemControl now forwards `disabled` to the rendered element and exposes it in its state and as `data-disabled`, like the other control parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Email and number inputs don't expose their caret, so the tree couldn't tell when it reached an edge and took Left and Right from them on every press. They now keep the arrows, like other non-text inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`disabled` isn't a `<div>` attribute, so the forwarded props failed to typecheck against the default element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Give the action tree checkbox, switch, Remove buttons and new-tab link 24px hit areas, like the expansion trigger, and keep the checkbox and trigger hit areas apart. - Darken the service traffic rate so it passes contrast on selected and hovered rows, and describe each row with its rate. - Show a contrasting inner focus ring on the active link item. - Keep the switch state and the filter input focus ring visible in forced colors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Revealing a focused row in the page went through `scrollIntoViewIfNeeded`, which sums `offsetTop` values and ignores how far the tree's own scroller is scrolled. After End in a scrolled list, it scrolled the page toward the row's unscrolled position and moved the tree off screen. The page now uses the same live-rect math as the inner containers, with the viewport as its scrollport. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `scroll-behavior: smooth` on the tree's scroller, assigning `scrollTop` starts an animation, so the page pass measured the row before it moved and scrolled the page past it. Each container now reports how far it will move the row, and the outer ones subtract that distance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous change returned the whole distance each container scrolled, so after an instant scroll the page pass subtracted a move the row's live position already showed, and scrolled the page away from it. Return only what's left after reading the position back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@base-ui/react/tree-grid` exported its root-level types only in the `TreeGrid` namespace, so the generated reference printed the Tree names behind them, such as `TreeRootActions`, which the package doesn't export. It now re-exports them under flat TreeGrid names, as it already does for the part props and states, and the reference prints `TreeGrid.Root.Actions` and the other namespace names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Tree.Item` said a click deselects the other items, which isn't true with `multiple`. `Tree.CheckboxItem` said it leaves the other items selected, which isn't true in single selection. `Tree.List` said it renders all the items at once, but it renders only the ones in view. The summaries now name what each part is, which holds in every mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pages Base UI is discussing a keyboard section on every component page, so the Tree page gets one back and the TreeGrid page gets its first, before the API reference as on the ListBox page. They describe the keys as the tree handles them now: the shared typeahead, Space and Enter, the selection modes, checkbox items, disabled rows and trees, the filter input, and the cell navigation of a tree grid. The components index picks up the new sections, and the example headings it was missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tree and TreeGrid pages now say that every row whose ancestors are expanded renders, including the ones scrolled out of view, next to the guidance for large trees. A row a virtualizer leaves out can't take focus from the keyboard yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The options type was `Tree.CreateItemsOptions`, with the flat alias `TreeCreateItemsOptions`. Combobox and ListBox export only a flat `Create<Component>ItemsOptions`, so the Tree now exports `CreateTreeItemsOptions`, and the TreeGrid `CreateTreeGridItemsOptions`, and neither namespace has a `CreateItemsOptions` member anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inline the leftover selection pass-through, share the first-selected-row lookup between the tab stop and the range anchor, memoize the select-all ids, derive checkbox toggling from the item kind, and run Space and Enter through one activation path. Tidy the related tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring select all back to two branches, share one known-item and one selectability check, check the disabled tree once for the tab stop, pass the toggled item to propagation directly, and read the row list once per typeahead scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`actionsRef.setItemSelection(id, false)` with parent propagation deselected every ancestor of the item, including selected ones that can't be selected, such as disabled ones. The ancestor walk now skips them, as the descendant walk does since 2871502. The walk goes on above a skipped ancestor. The item is a descendant of every ancestor, so an enabled ancestor above a disabled one no longer has all of its selectable descendants selected and must be deselected. Stopping there would leave it selected over an unselected descendant, which neither propagation nor checkbox state produces elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lection
With `Tree.FilterProvider`, Ctrl+A kept the selected items the filter
hides, while a Shift range, a press with `multiple="opt-in"` and the
selection following the arrow keys dropped them. Every gesture that
replaces the selection now keeps them, as it keeps selected items that
can't be selected: users can't deselect either while it's out of reach.
ListBox has no filter of its own, only filtered `items`, which the Tree
already treats like it (`filter={null}` drops the ids it no longer
knows). So the rule follows the option that loses less user data.
Ctrl+A goes through the same replacement, so while filtering it reports
the shown items in tree order before the hidden ones it keeps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `multiple`, ListBox and Select accept `value={null}`, but the
Tree's types rejected `selectedItems={null}` and
`defaultSelectedItems={null}`, so apps that keep "no selection" as
`null` needed a cast for the Tree only. Both props now accept `null` in
every mode. With multiple selection the root stores it as `[]`, so a
change that leaves the selection empty isn't reported as one.
`onSelectedItemsChange` still receives an array with `multiple`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tree reported highlights as `'item-press' | 'keyboard' | 'imperative-action' | 'none'`, while master's Select, Menu, Combobox and Autocomplete, and ListBox, report `'keyboard' | 'pointer' | 'none'`, so an `onItemHighlighted` handler written for one didn't compile for the other. The tree now records the event that moves focus, as before, and derives the reason from it with `getHighlightReason`: - a key press reports `'keyboard'` with its keydown; - a press on a row, its expansion trigger or `Tree.Label` reports `'pointer'` with the press, recorded before focus moves, as ListBox records the event behind a highlight; - anything else reports `'none'` with the real focus event, such as tabbing in, `actionsRef.focusItem()` or focus recovery. The "keyboard can move faster than a group expands" branch reads the same derived reason, and a new test covers it. Breaking change: `TreeRootHighlightEventReason` drops `'item-press'` and `'imperative-action'` and adds `'pointer'`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Master reports keyboard navigation in lists as `'list-navigation'`: Select, Combobox, Menu and NavigationMenu, including a submenu opened with Arrow Right. ListBox reports keyboard selection the same way. `'keyboard'` is only for highlights and for keyboard value editing, such as in Slider or NumberField. The Tree reported both as `'keyboard'`. Now: - selection changes made by the keys that move focus (arrows, Home/End, Page Up/Page Down and typing, with Shift or with `multiple="opt-in"`) and by Ctrl/Cmd+A report `'list-navigation'`, in TreeGrid cells too; - expansion changes made by Arrow Right, Arrow Left, `*` and TalkBack's expand and collapse actions report `'list-navigation'`; - Space and Enter still go through the row's click and report `'item-press'`. The "keyboard can move faster than a group expands" branch reads the highlight reason, which stays `'keyboard'`, so it's unaffected. Breaking change: `TreeRootSelectionChangeEventReason` and `TreeRootExpansionChangeEventReason` replace `'keyboard'` with `'list-navigation'`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Neither part is a form control: the query is UI state, and a row checkbox only selects its row. Both now render a `form` that names no element, so Enter in them no longer submits a surrounding form. `Tree.Input` drops `name` and `form` from its props. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A disabled `Field.Root` disabled `TreeGrid.RowCheckbox` while its row stayed selectable. The checkbox now shields the Field, Field.Item and CheckboxGroup contexts, so only the tree decides whether a row can be selected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clicking the label did nothing in an empty or fully filtered tree. It now focuses the tree container, which holds the tab stop then, like `Listbox.Label` focuses the list. A disabled tree still ignores the click. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ListBox, Select and Combobox lists take optional children, so a list or root rendered without content needed a type workaround here. Without children, the roots render nothing and the list renders an empty tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tree and TreeGrid pages describe `multiple` and `multiple="opt-in"` without a demo, and recommend a visible label that no demo renders. Each page gets a demo per mode, and both heroes name the tree with its label instead of `aria-label`. The TreeGrid page now has its own opt-in section, like the Tree page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ches Also drop the unused proposal settlement callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reconcile only the parents an items change touches, deepest first, through the propagation walk; skip the hierarchy diff when no propagation can apply. Share one tab-stop focus helper between the label and focus recovery, one selection-follows-focus method between the Tree and TreeGrid, and one CSS module between the Tree demos. Drop leftovers from the removed proposal callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Let the selection plugin own whether propagation can apply, share one order-insensitive comparison, return early from the reconcile when nothing propagates, reuse walked subtrees in the parent check, and keep the TreeGrid hero's own styles apart from the shared demo module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tree.Label now calls useLabel, so clicks on nested controls no longer move focus and double clicks don't select its text. It doesn't label an enclosing Field's control, and it no longer accepts `id`, like the root labels of Select and Combobox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… gesture Ctrl/Cmd+Arrow Up/Down, with or without Shift, moved focus in every selection mode. Like Listbox, the tree now ignores it unless it's the focus-only gesture of multiple="opt-in", which Alt no longer joins on Windows and Linux. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shared parts named Tree parts in TreeGrid errors, warnings and API summaries. The filter part error and the unknown filteredItems warning now name the namespace of the root they render in, and link to its page. The other shared messages and summaries use neutral wording, and the missing root and item context errors name the parts of both components. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tree.List, TreeGrid.Table, TreeGrid.Collection and the FilterProvider
parts took an item type argument. Like Combobox.List and Select.Value,
they now type the item as `any`, and the docs annotate the render
function's parameter instead: `{(node: Node) => …}`. The roots keep
inferring the item type from `items`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preview: https://deploy-preview-6212--base-ui.netlify.app/react/components/tree and https://deploy-preview-6212--base-ui.netlify.app/react/components/tree-grid
Experiments with columns: document outline and account hierarchy
Work on #3327.
Adds two components that share one implementation:
Treefollows the tree view pattern: the list is atree, and each item is atreeitemthat the keyboard focuses as one element.TreeGridfollows the treegrid pattern: each item is arowof one or more cells, which hold values and controls the keyboard reaches: buttons, inputs, links, checkboxes.Both take the same root props (items, expansion, selection,
actionsRef, transactions) and share filtering, status messages, group transitions, and the item decorations.Usage
A basic tree:
Checkbox selection, where the item itself is the checkbox (
aria-checked,mixedfor a partly selected branch):A navigation tree, where the item is the link, as in the APG navigation tree view:
Rows with controls:
Columns, named by a header row:
Filtering comes from a provider that wraps either root, so trees without it don't bundle the filter:
Notes
Why two components
A
treeitem is one focusable element that screen readers read as a whole, so it can't hold controls the keyboard reaches. Atreegridrow can, through its cells. The two patterns need different markup (TreeGrid.Cellis the cell, and the controls are parts inside it) and different keyboard models, so each gets its own component, as Base UI does with one primitive per accessibility pattern.TreeGridis named after the pattern. It covers trees whose rows carry controls, in one column or several, but not tabular data: it doesn't sort, resize, edit or page through its rows, and the docs point to a data grid for those.Each part belongs to one component. A grid part in a
Tree.Root(<TreeGrid.CellButton>,<TreeGrid.Cell>, …) or a tree part in aTreeGrid.Root(<Tree.CheckboxItem>,<Tree.LinkItem>) throws an error that names the part to use instead.Why
Tree.CheckboxItemandTreeGrid.RowCheckboxboth existIn a
Tree, the item is the checkbox: it reportsaria-checked, a click toggles it, and Shift+click selects a range. In aTreeGrid, the checkbox is a control inside a cell, next to the others. The same split givesTree.LinkItem(the item is the link) andTreeGrid.CellLink(a link inside a cell).Why
TreeGriduses table namesTreeGrid.Tableis thetreegrid,TreeGrid.Rowtherowthat takes focus and carries the selection, level and expansion, andTreeGrid.Cellagridcell. Screen readers don't read content placed directly in a row, so it needs a cell (the tree grid warns when a row renders none). The row is named after its item, so a focused row announces only its label. A cell takes its name from its content, which keeps the visible text of its controls in it, as WCAG 2.5.3 (label in name) requires.The parts that act on the row take a
Rowprefix (RowCheckbox,RowExpansionTrigger,RowIndentGuide,RowGroupIndicator), and the controls aCellprefix (CellButton,CellInput,CellLink,CellControl), sinceTreeGrid.Inputis already the filter input shared withTree. The data keeps its names:items,itemId,createItems.The header row has to sit inside the
treegridelement, soTreeGrid.Tabletakes either the row render function, or the header row andTreeGrid.Collection, which renders the rows without an element of its own. That's the splitCombobox.ListandCombobox.Collectionalready make.How the keyboard moves through columns
tabindexwhile the keyboard is on it, so a click on its text still focuses the row.TreeGrid.HeaderCell, and when a row renders a different number of cells than the header row.Why items are data rendered by
Tree.ListandTreeGrid.Table, not nested JSXUnlike Menu or Accordion, both components read their hierarchy from
items, and render each row with a function. Keyboard navigation, select all, selection propagation, filtering andapplyTransaction()need every item, including the ones inside collapsed folders that never mount. Rows render as flat siblings witharia-level, like the APG examples.Why tree grid controls are dedicated parts
Like
Toolbar.Button,Toolbar.InputandToolbar.Linkjoin the toolbar's roving focus,TreeGrid.CellButton,TreeGrid.CellInput,TreeGrid.CellLinkandTreeGrid.CellControlregister with their row. The arrow keys then move between the row and its controls, and the keys a control needs, such as the arrows in a text input, stay with it. Other elements join throughrender, as with Toolbar.Why a row click doesn't select the descendants
In multiple selection, clicking a
Tree.Itemrow selects only that row, while checking aTree.CheckboxItemor aTreeGrid.RowCheckboxalso selects its descendants (checkboxSelectionPropagation). Libraries split on this:Details and sources are in this survey.
Follow-up
keepsHorizontalArrowinTreeGridPluginalready does. Once it lands, the two can share one helper.Benchmarks
Headless Tree View
Design Systems
Specialized Libraries
No Tree Component
Radix (React), Headless UI (Tailwind), daisyUI, NextUI, TanStack, Evergreen
Known issues
No warning when touch screen readers can't expand a tree grid row
Touch screen readers can't press arrow keys, so iOS VoiceOver and TalkBack users expand a row through
RowExpansionTrigger. The docs ask for it, but nothing warns when an expandable row renders no trigger andexpandOnClickis off. Chromium's source suggests it matters forTreeGrid: Blink turns TalkBack's Expand action into an arrow key only fortreeitem, and into a click for other roles (ax_object.cc), so on atreegridrow it would select instead of expanding. ATreeitem is atreeitem, so it isn't affected. That's inferred from the source, not tested. React Aria warns in development in this case (Tree.tsx). Decide after a screen reader pass on a phone whetherTreeGridshould warn too.Screen readers don't hear which items match the filter
Items are named after their label with
aria-label, so screen readers don't readdata-filter-matchor anything else inside a row. While filtering, a user can't tell a match from an ancestor kept for context, or from the other items in the modes that keep every item;Tree.Statusonly announces the number of results. None of the libraries with built-in filtering solves this: Trees.software, PrimeReact, Ant Design, AG Grid, the MUI X Data Grid, react-arborist and jsTree mark matches only visually, or not at all. The closest is VS Code, whose arrow keys land only on matches while its find widget is open (abstractTree.ts). We don't copy that, since the APG tree pattern moves through every visible item. The filtering demos describe matches witharia-description="Match"instead, and the docs ask for the same. A built-in description would need a translatable string merged with the developer's own description, so it can wait until users ask for it.TreeGrid should support
selectionMode="none"We removed
selectedMode="none"and aligned the DX of the Tree with Select / ListBox and Combobox (with amultipleprop).But this use case does make sense on the
TreeGrid, we need to add it back.🤖 Generated with Claude Code