Repository navigation
feat(base-ui): port Menu submenus (Phase 3f stage 3), completing the menu subpath - #322
Merged
Merged
Conversation
…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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
5 tasks done
3 of 5 tasks
7 of 10 tasks
This branch was previously 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.
Summary
Menusubmenus — Phase 3f stage 3 of 4, on top of feat(base-ui): port the Menu item family (Phase 3f stage 2) #318.Menu.SubmenuRootandMenu.SubmenuTrigger. All 20 upstreammenuparts are now in place — themenusubpath is complete.Why
SubmenuRootsuppliesMenuSubmenuRootContext— the context stage 1 declared but nothing provided — which is what makes a nestedMenuRootresolve 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 relaysMenuPositionerhas carried inertly since stage 1.SubmenuTriggeris also the first user of thesubmenu-triggerarm ofuseMenuItem'sitemMetadata, ported in stage 2 and unreachable until now.Changes
packages/base-ui/src/menu.ts(+233 lines):MenuSubmenuRootandMenuSubmenuTrigger, plus thetriggerOpenStateMappinganduseTriggerRegistrationimports they need.The trigger holds two stores at once — it is an item of the parent menu (parent
CompositeList,itemProps,isActive, parenttypingRef) and the trigger of its own menu (own store, own open state, own hover/click interactions). Upstream'sdelete rootTriggerProps.idis 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
isElementDisabledwarning is dropped — this package carries noNODE_ENVbranches.A second rig limitation — and why I did not normalise it away
The open-submenu fixture diverged on exactly one attribute:
data-highlightedon the submenu trigger. Everything else — the entire nested positioner,data-nested,inline-endplacement, 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'sonFocussets the parent store'sactiveIndex. Both runtimes share onedocument.activeElement, so only one can win — and unlike the focus-guardtabindexfrom 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:
— identical to React.
Normalising
data-highlightedaway 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 inmenu.test.ts.Escape semantics, probed not assumed
My first test asserted that Escape closes only the child. It failed. Probing three dispatch targets:
document.submenu-popup.menu-subtriggerFrom inside the tree it closes only the child — that is
closeParentOnEscdefaulting to false. Ondocumentboth close, because that target is outside both floating elements and each menu dismisses independently. The single-level tests from stage 1 can usedocumentprecisely 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-labelledbyround trip (which is what thedelete rootTriggerProps.idline protects); the trigger highlighted while open; nested placement,data-nested, and a shareddata-rootowneridacross levels.namespace-parts.test.tsnow lists the complete upstream surface.Two tests I wrote and then dropped rather than leave unreliable:
SubmenuTriggerrenders inside a portal, so the error escapes as an unhandled exception rather than propagating out ofmount(). 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:checkpnpm typecheck(repo-wide, exit 0)pnpm test— 1420 files / 14,338 tests passedpnpm cli:data:check,pnpm bindings:status:checkpnpm --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
MenubarandContextMenu(+useClientPoint, already ported), which fill in themenubar/context-menuparent 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.safePolygon,restMs,shouldOpenagainst the parent'sallowMouseEnter) but not covered by tests — hover timing needs real pointer geometry, which jsdom does not provide. The interactive fixture usesopenOnHover={false}for that reason.🤖 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/menuport by addingMenu.SubmenuRootandMenu.SubmenuTrigger, so all 20 upstream menu parts are exposed.SubmenuRootsuppliesMenuSubmenuRootContextso nested roots see{ type: 'menu' }and nested placement/data-nestedbehavior can run.SubmenuTriggeris the first use of thesubmenu-triggeruseMenuItemmetadata 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,
stepComparingSubtreeon the nested portal (avoids a shared-documentdata-highlightedfocus 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.