Skip to content

Port the Base UI list-navigation and typeahead infrastructure (Phase 3e) - #308

Merged
trueadm merged 4 commits into
mainfrom
feat/base-ui-list-navigation
Jul 27, 2026
Merged

trueadm merged 4 commits into
mainfrom
feat/base-ui-list-navigation

Conversation

@trueadm

@trueadm trueadm commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Ports the whole of Base UI Phase 3e — the list-navigation and typeahead infrastructure — into @octanejs/base-ui, transcribed from Base UI 1.6.0.
  • Not for merge on its own. Per the one-deliverable decision, this branch merges once the Menu family lands on top of it; Menu is the first real consumer and is what proves the infrastructure. Opened now so the infrastructure half is reviewable while Menu is ported onto the same branch.

Why

3e is pure infrastructure with no consumer until Menu/Select/Combobox exist. Landing it alone would leave the differential rig nothing to render and no behavior test exercising it — the same shape as the openOnHover stub that sat inert and unflagged for months. Hence: review now, merge with Menu.

Changes

useListNavigation (930 loc upstream) — arrow-key navigation over a list using either real DOM focus or virtual focus (aria-activedescendant), returning the { reference, floating, item, trigger } bags Menu, Select and Combobox merge onto their parts. octane adaptations: reads the FloatingRootStore (store.useState/select/setOpen/context); events are native, so event.nativeEvent collapses to event; useIsoLayoutEffect is octane's useLayoutEffect, and because a plain-.ts hook is not compiled, an undefined dep array runs the effect every render, matching upstream's dep-less form; every composed hook threads an explicit sub-slot. The two dev-only console.warn misconfiguration guards are dropped — this package carries no process.env.NODE_ENV branches.

Grid navigation — utils/composite/grid-utils.ts holds the two-dimensional algorithm and the cell-map helpers, with the two gridNavigation entry points beside their consumers: utils/floating/gridNavigation.ts (the uniform 1x1 navigator useListNavigation injects into its own grid option) and utils/composite/gridNavigation.ts (the navigator a composite passes to useCompositeRoot). grid stays injected rather than imported, so a consumer that never passes it leaves the grid helpers out of its bundle entirely — that is the point of the injection. useListNavigation types the option as GridNavigator, which gridNavigation satisfies structurally.

useTypeahead — matches list items as the user types, the way a native <select> does; pairs with useListNavigation.

Supporting utilities — TimeoutManager (several keyed timeouts behind one handle, distinct from useTimeout's single-timeout Timeout), RequestQueue, getPseudoElementBounds, useMixedToggleClickHandler.

Upstream-drift fix (behavioral). Porting useListNavigation exposed that the vendored list-navigation helpers in utils/composite/list-utils.ts had drifted from Base UI 1.6.0: isListIndexDisabled neither skipped invisible items nor kept the disabled/aria-disabled attribute fallback separate from an explicit disabledIndices. useListNavigation depends on that separation — it deliberately omits disabledIndices when choosing the item to focus on open so attribute-disabled items are still skipped for consumers passing an empty array (mui/base-ui#2604). list-utils now matches upstream's body and signatures (item array for the index helpers, ref for getMinListIndex/getMaxListIndex), and useCompositeRoot drops the { current } wrappers it needed for the old shape. This changes the already-shipped composite roving focus — hidden items are now skipped — so it carries a patch changeset. REASONS.listNavigation was added alongside.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — 13,937 tests / 1,399 files, all passing

Risk / follow-ups

  • No tests for the new hooks yet, on purpose rather than by omission: a differential test needs a rendered component, and the first one arrives with Menu. That is the reason this branch does not merge alone.
  • The one behavioral change to already-shipped code is the isListIndexDisabled fidelity fix above; it is covered by the existing composite suite and carries a changeset.
  • Follow-ons after Menu: Menubar (217 loc) and ContextMenu (433 loc, useClientPoint already ported) are cheap.

🤖 Generated with Claude Code


Note

Medium Risk
Large, accessibility-critical keyboard/focus surface with a behavioral change to existing composite navigation; risk is moderated because it tracks upstream 1.6.0 and has no Menu/Select consumer wired in this PR alone.

Overview
Phase 3e brings Base UI’s floating list infrastructure into @octanejs/base-ui: useListNavigation (arrow keys, real or virtual focus via aria-activedescendant, { reference, floating, item, trigger } prop bags) and useTypeahead (type-to-match, meant to pair with list navigation). Grid support is opt-in via injection—grid-utils plus separate gridNavigation factories for useCompositeRoot (multi-cell grids) and useListNavigation (uniform 1×1 grids)—so Menu/Select-style consumers can tree-shake the heavy grid code.

Also adds small upstream utilities: RequestQueue, TimeoutManager, getPseudoElementBounds, useMixedToggleClickHandler, and REASONS.listNavigation for open/close details.

Shipped behavior change: vendored list-utils now matches Base UI 1.6.0’s isListIndexDisabled (explicit disabledIndices wins; invisible items always skipped; disabled/aria-disabled only when no disabledIndices was passed). useCompositeRoot call sites were updated for array-based helpers—composite roving focus now skips non-visible items (patch changeset).

Reviewed by Cursor Bugbot for commit 90b44ae. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 4 commits July 27, 2026 14:57
First piece of Phase 3e (list navigation + typeahead), which lands together with
the Menu family so the navigation infrastructure has a real consumer rather than
sitting untested.

TimeoutManager holds several keyed timeouts behind one handle, so a caller can
start, replace and cancel each independently and drop them all on teardown. It is
distinct from `utils/useTimeout`'s `Timeout`, which owns exactly one. Pure, so it
is a straight transcription with no renderer adaptation.

No consumer yet — Menu's typeahead and submenu timing are what use it. Untested
on purpose rather than by omission: a differential test needs a rendered
component, and the first one arrives with Menu.

Co-Authored-By: Claude Opus 5 <[email protected]>
…gleClickHandler

Three more Phase 3e helpers, landing with the Menu family so the navigation
infrastructure has real consumers rather than sitting untested.

RequestQueue tracks each key's lifecycle through queued -> pending and caps
in-flight requests, with `pickEntries` as the subclass hook for ordering (FIFO by
default). getPseudoElementBounds widens an element's box to cover its
::before/::after, so hit-testing accounts for decorations drawn outside it; it
short-circuits under jsdom, where getComputedStyle with a pseudo-element is not
implemented. Both are pure, so they are straight transcriptions.

useMixedToggleClickHandler is a hook, so it follows the binding's plain-`.ts`
convention: the caller's slot arrives as the trailing argument via `splitSlot`
and the `useRef`/`useMemo` it composes take derived sub-slots. Its events are
native rather than synthetic, so the handlers take the native event and
`preventBaseUIHandler` is the shim `mergeProps` attaches. Upstream's empty
`UseMixedToggleClickHandlerState` interface is a docs-pipeline artifact with no
members and is dropped.

No consumers yet — Menu's trigger and submenu behavior are what use these.
Untested on purpose rather than by omission: a differential test needs a rendered
component, and the first one arrives with Menu.

Validation: `tsrx-tsc --noEmit` on @octanejs/base-ui and `pnpm format:check`,
both clean. No test run — these files have no consumer and no test yet.

Co-Authored-By: Claude Opus 5 <[email protected]>
The largest piece of Phase 3e (list navigation + typeahead), which lands together
with the Menu family so the navigation infrastructure has a real consumer rather
than sitting untested.

useListNavigation adds arrow-key navigation over a list of items using either real
DOM focus or virtual focus (`aria-activedescendant`), and returns the
`{ reference, floating, item, trigger }` prop bags Menu, Select and Combobox merge
onto their parts. octane adaptations: it reads the FloatingRootStore
(`store.useState`/`select`/`setOpen`/`context`); events are native, so
`event.nativeEvent` collapses to `event`; `useIsoLayoutEffect` is octane's
`useLayoutEffect`, and because a plain-`.ts` hook is not compiled, an `undefined`
dep array runs the effect every render, matching upstream's dep-less form; every
composed hook threads an explicit sub-slot. The two dev-only `console.warn`
misconfiguration guards are dropped — this package carries no
`process.env.NODE_ENV` branches.

The `grid` option stays injected rather than imported, so non-grid consumers keep
the grid helpers out of their bundles. It is typed here as `GridNavigator`, which
the `gridNavigation` port satisfies structurally.

Porting this exposed that the vendored list-navigation helpers had drifted from
Base UI 1.6.0: `isListIndexDisabled` neither skipped invisible items nor kept the
attribute fallback separate from an explicit `disabledIndices`. useListNavigation
depends on that separation — it deliberately omits `disabledIndices` when choosing
the item to focus on open so attribute-disabled items are still skipped for
consumers passing an empty array (mui/base-ui#2604). `list-utils` now matches
upstream's body and signatures, and `useCompositeRoot` drops the `{ current }`
wrappers it needed for the old shape. That is a behavior fix for the already
shipped composite roving focus, so it carries a changeset.

No consumer yet — Menu is what uses this. Untested on purpose rather than by
omission: a differential test needs a rendered component, and the first one arrives
with Menu.

Validation: `tsrx-tsc --noEmit` clean, `vitest --project base-ui` 96/96 green,
prettier clean on the changed files.

Co-Authored-By: Claude Opus 5 <[email protected]>
Ports three Base UI 1.6.0 sources for the list-navigation infrastructure:

- `floating-ui-react/hooks/gridNavigation.ts` -> `utils/floating/gridNavigation.ts`,
  the uniform 1x1 navigator `useListNavigation` injects for its own `grid` option.
- `internals/composite/root/gridNavigation.ts` -> `utils/composite/gridNavigation.ts`,
  the cell-map-backed navigator a composite passes to `useCompositeRoot`'s `grid`
  prop. Two different upstream files, kept separate.
- `floating-ui-react/hooks/useTypeahead.ts` -> `utils/floating/useTypeahead.ts`,
  native-event and slot-threaded like the other floating hooks.

Both navigators need the grid half of upstream's `floating-ui-react/utils/composite.ts`
(`getGridNavigatedIndex` and the cell-map helpers), which had no counterpart here;
it lands as `utils/composite/grid-utils.ts`, beside the list algebra this binding
already vendors into `list-utils.ts`. It depends on that module's Base UI 1.6.0
signatures, which arrive with `useListNavigation`.

No consumer until Menu lands, so no tests yet.

Co-Authored-By: Claude Opus 5 <[email protected]>
@vercel

vercel Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 27, 2026 4:30pm
octane-website-mcp Ready Ready Preview, Comment Jul 27, 2026 4:30pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 27, 2026 16:29 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 27, 2026 16:30 Inactive
@trueadm
trueadm merged commit de6c342 into main Jul 27, 2026
28 checks passed
@trueadm
trueadm deleted the feat/base-ui-list-navigation branch July 27, 2026 19:54
trueadm added a commit that referenced this pull request Jul 27, 2026
… stage 1) (#316)

* feat(base-ui): port the Menu open/close + roving-focus path (Phase 3f stage 1)

`@octanejs/base-ui/menu` now exposes `Menu.Root`, `Menu.Trigger`, `Menu.Portal`,
`Menu.Positioner`, `Menu.Popup`, `Menu.createHandle` and `Menu.Handle`, ported
from `@base-ui/react` 1.6.0's `menu/store`, `menu/root`, `menu/trigger`,
`menu/portal`, `menu/positioner` and `menu/popup`.

This is the first CONSUMER of the Phase 3e list-navigation infrastructure, which
merged (#308) deliberately untested because a differential test needs a rendered
component. `MenuRoot` wires `useListNavigation` + `useTypeahead` to the popup
store and `Menu.Positioner` wraps the popup in the `CompositeList` that feeds
their element/label refs. 3e needed no repairs.

Supporting additions: `useOpenInteractionType` (only the stateless
`useOpenMethodTriggerProps` half had been ported, since Popover keeps
`openMethod` in its store), `DROPDOWN_COLLISION_AVOIDANCE` /
`TYPEAHEAD_RESET_MS` / `PATIENT_CLICK_THRESHOLD` in `utils/constants` (Popover's
local copy of the last one now imports it), `findRootOwnerId`, and the
`cancel-open` / `sibling-open` change reasons.

`MenubarContext` and `ContextMenuRootContext` land as context-only modules ahead
of their components (stage 4), so Menu's ~dozen `parent`-union branches are
transcribed verbatim rather than stubbed and re-threaded later. Nothing provides
them yet, so those branches are inert.

Tests: 5 differential fixtures (closed trigger; open modal, non-modal, explicit
placement, and disabled roots) plus 6 behavior tests for what the rig cannot
see — click toggle, arrow-key open, Escape dismiss, the ARIA contract,
`aria-orientation` reaching the popup from `useListNavigation`, and focus
entering the popup and returning to the trigger.

A `Menu.Popup` takes focus on open and the rig mounts both runtimes in one jsdom
document, so whichever popup is focused last makes the other runtime's portal
see an outward `focusout` and run `disableFocusInside`, rewriting that portal's
focus-guard `tabindex`. Both runtimes run identical code; the asymmetry is one
`document.activeElement` for two apps. `parity.test.ts` normalises the guards'
tabindex away for the open-menu fixtures and byte-compares everything else.

Items, submenus, `Viewport`/`Arrow`/`Backdrop`/`Separator`, `Menubar` and
`ContextMenu` land in stages 2-4.

Co-Authored-By: Claude Opus 5 <[email protected]>

* test(base-ui): cover Menu's detached-trigger and handle open/close path

Review flagged `MenuRoot`'s floating root context as never installed on
`MenuStore`. It is — `usePopupInteractionProps` syncs its whole state part, and
`floatingRootContext` is in it, exactly as upstream `MenuRoot.tsx` does it. The
real gap was coverage: nothing exercised the path that routes through
`MenuStore.setOpen` → the context's event bus. A normal trigger click goes
through `FloatingRootStore.setOpen` → `onOpenChange` instead, so it would not
have caught a dead bus.

Adds a `MenuWithHandle` fixture whose `Menu.Trigger` is a SIBLING of `Menu.Root`,
associated only by a shared `MenuHandle`, and tests that open through the
detached trigger, close through `handle.close()`, reopen through
`handle.open(triggerId)` with the popup's `aria-labelledby` resolving to that
trigger, and throw for an unregistered id.

Negative control: deleting `floatingRootContext` from that state part fails six
of the eight tests in `tests/menu.test.ts`.

Also documents the install site — Menu cannot build its context in the store
constructor the way Dialog/Popover do, because its store may be an external
`MenuHandle` store shared with triggers outside the Root, so the context must be
created by the Root that owns `setOpen` and published from there.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 90b44ae5 Deployed Jul 27, 2026 by vercel[bot]
Preview – octane-website-mcp — 90b44ae5 Deployed Jul 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant