Skip to content

feat(base-ui): port Menu submenus (Phase 3f stage 3), completing the menu subpath - #322

Merged
trueadm merged 1 commit into
mainfrom
feat/base-ui-menu-submenus
Jul 27, 2026
Merged

trueadm merged 1 commit into
mainfrom
feat/base-ui-menu-submenus

Conversation

@trueadm

@trueadm trueadm commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Why

SubmenuRoot supplies MenuSubmenuRootContext — the context stage 1 declared but nothing provided — which is what makes a nested MenuRoot resolve its parent to { type: 'menu' }. That one link switches on a lot of already-ported machinery: nested positioner placement, data-nested, the suppressed nested backdrop, closeParentOnEsc, and the sibling-close / parent-close / item-hover relays MenuPositioner has carried inertly since stage 1.

SubmenuTrigger is also the first user of the submenu-trigger arm of useMenuItem's itemMetadata, ported in stage 2 and unreachable until now.

Changes

packages/base-ui/src/menu.ts (+233 lines): MenuSubmenuRoot and MenuSubmenuTrigger, plus the triggerOpenStateMapping and useTriggerRegistration imports they need.

The trigger holds two stores at once — it is an item of the parent menu (parent CompositeList, itemProps, isActive, parent typingRef) and the trigger of its own menu (own store, own open state, own hover/click interactions). Upstream's delete rootTriggerProps.id is transcribed verbatim, mutation included: the trigger owns its own id because it is also a parent item, so the root's trigger props must not stamp one over it.

Upstream's dev-only isElementDisabled warning is dropped — this package carries no NODE_ENV branches.

A second rig limitation — and why I did not normalise it away

The open-submenu fixture diverged on exactly one attribute: data-highlighted on the submenu trigger. Everything else — the entire nested positioner, data-nested, inline-end placement, ids, aria wiring — matched byte for byte.

Cause: while its submenu is open the trigger is the only tabbable child of the parent popup (tabIndex: open || highlighted ? 0 : -1), so the parent's focus manager focuses it, and the trigger's onFocus sets the parent store's activeIndex. Both runtimes share one document.activeElement, so only one can win — and unlike the focus-guard tabindex from stage 1, this is derived store state, which no DOM-level normaliser can reconstruct.

I confirmed it is the rig and not the port by mounting octane alone, with no React competing for focus:

OCTANE-ALONE highlighted=true subtrigger-tabindex=0 active=menu-subtrigger anyHighlighted=1

— identical to React.

Normalising data-highlighted away would blind the roving-focus comparison that stage 2's helper deliberately preserves. So instead the open-submenu case byte-compares the submenu's own portal subtree (stepComparingSubtree), which is where the whole stage-3 payload lives: nested placement, data-nested, the popup's aria wiring back to the trigger, and the nested items. The trigger's highlighted state is asserted octane-only in menu.test.ts.

Escape semantics, probed not assumed

My first test asserted that Escape closes only the child. It failed. Probing three dispatch targets:

Escape dispatched on parent submenu
document closes closes
.submenu-popup stays open closes
.menu-subtrigger stays open closes

From inside the tree it closes only the child — that is closeParentOnEsc defaulting to false. On document both close, because that target is outside both floating elements and each menu dismisses independently. The single-level tests from stage 1 can use document precisely because there is only one menu. The test now uses the realistic target and the comment explains the distinction.

Tests

2 differential fixtures: a closed submenu (whole-container compare — the trigger's dual item+trigger prop set, roving tabindex, aria-haspopup), and an open submenu (portal-subtree compare, per above).

4 behavior tests: open-from-trigger then child-only Escape; the aria-expanded / aria-controls ↔ aria-labelledby round trip (which is what the delete rootTriggerProps.id line protects); the trigger highlighted while open; nested placement, data-nested, and a shared data-rootownerid across levels.

namespace-parts.test.ts now lists the complete upstream surface.

Two tests I wrote and then dropped rather than leave unreliable:

  • A "focus lands in the submenu" assertion — passed in isolation, failed in a full run, because focus leaks between tests in the shared jsdom document. Opportunistic, not core to the behavior under test.
  • A "throws outside SubmenuRoot" guard test — SubmenuTrigger renders inside a portal, so the error escapes as an unhandled exception rather than propagating out of mount(). Not worth an unhandled error in the runner.

The base-ui suite was run three times to confirm stability after removing the flaky one.

Validation

  • pnpm format:check
  • pnpm typecheck (repo-wide, exit 0)
  • pnpm test — 1420 files / 14,338 tests passed
  • pnpm cli:data:check, pnpm bindings:status:check
  • targeted: pnpm --filter @octanejs/base-ui exec tsrx-tsc --noEmit -p tsconfig.json; pnpm vitest run --project base-ui (129 passed, 3× for stability)

Risk / follow-ups

  • Stage 4 (~650 loc): Menubar and ContextMenu (+ useClientPoint, already ported), which fill in the menubar / context-menu parent branches transcribed in stage 1 and provide the two context-only modules from feat(base-ui): port the Menu open/close + roving-focus path (Phase 3f stage 1) #316. Those branches remain inert until then.
  • Submenu open-on-hover is ported (safePolygon, restMs, shouldOpen against the parent's allowMouseEnter) but not covered by tests — hover timing needs real pointer geometry, which jsdom does not provide. The interactive fixture uses openOnHover={false} for that reason.
  • SSR/hydration coverage for open menus is still not added.

🤖 Generated with Claude Code


Note

Medium Risk
Touches nested menu focus, floating dismiss (Escape), and dual parent/child store wiring in a user-facing overlay path, though changes are scoped to new submenu parts with strong test coverage.

Overview
Completes the @octanejs/base-ui/menu port by adding Menu.SubmenuRoot and Menu.SubmenuTrigger, so all 20 upstream menu parts are exposed. SubmenuRoot supplies MenuSubmenuRootContext so nested roots see { type: 'menu' } and nested placement/data-nested behavior can run. SubmenuTrigger is the first use of the submenu-trigger useMenuItem metadata path and wires the parent menu’s composite item state together with its own trigger store (hover/click, safePolygon, sibling/parent close relays).

Differential coverage adds closed-submenu fixtures and, for the open-submenu case, stepComparingSubtree on the nested portal (avoids a shared-document data-highlighted focus race on the parent trigger). Behavior tests cover open/close, child-only Escape, ARIA wiring, highlight while open, and nested layout. Status/docs/changeset reflect Menu as complete; Menubar and ContextMenu stay for stage 4.

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

…menu subpath

Adds `Menu.SubmenuRoot` and `Menu.SubmenuTrigger`, ported from `@base-ui/react`
1.6.0's `submenu-root/` and `submenu-trigger/`. All 20 upstream `menu` parts are
now in place.

`SubmenuRoot` provides `MenuSubmenuRootContext` — the context stage 1 declared
but nothing supplied — which is what makes the nested `MenuRoot` resolve its
parent to `{ type: 'menu' }`. `SubmenuTrigger` is the first user of the
`submenu-trigger` arm of `useMenuItem`'s `itemMetadata`, and opening a submenu
activates the sibling-close, parent-close and item-hover relays `MenuPositioner`
has carried inertly since stage 1. It holds two stores at once: it is an item of
the parent menu and the trigger of its own.

A second rig limitation, deliberately NOT normalised away. With a submenu open,
its trigger is the only tabbable child of the parent popup, so the parent focus
manager focuses it and the trigger's `onFocus` sets the PARENT store's
`activeIndex` → `data-highlighted`. Both runtimes share one
`document.activeElement`, so only one can win, and unlike the focus-guard
`tabindex` this is derived STORE state that no DOM normaliser can reconstruct.
Confirmed it is the rig, not the port, by mounting octane alone: the trigger is
highlighted and focused, matching React exactly. Normalising `data-highlighted`
away would blind the roving-focus comparison stage 2 deliberately preserved, so
the open-submenu case byte-compares the submenu's OWN portal subtree instead —
nested placement, `data-nested`, aria wiring, nested items — and the highlighted
state is asserted octane-only.

Escape semantics were probed rather than assumed: from inside the tree it closes
only the child (`closeParentOnEsc` defaults to false); on `document` it closes
both, since that target is outside both floating elements.

Two tests were written and then dropped rather than left unreliable: a
focus-lands-in-the-submenu assertion that passed alone but not in a full run
(focus leaks between tests in the shared document), and a guard-throws test
whose error escapes as an unhandled exception because `SubmenuTrigger` renders
inside a portal.

Also regenerates `packages/cli/src/data/octane-data.json` for the status change.

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 10:42pm
octane-website-mcp Ready Ready Preview, Comment Jul 27, 2026 10:42pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 27, 2026 22:41 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 27, 2026 22:42 Inactive
@trueadm
trueadm merged commit 962ca64 into main Jul 27, 2026
28 checks passed
@trueadm
trueadm deleted the feat/base-ui-menu-submenus branch July 27, 2026 22:50

This branch was previously deployed

2 inactive deployments
Preview – octane-website — e72b9bea Deployed Jul 27, 2026 by vercel[bot]
Preview – octane-website-mcp — e72b9bea 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