feat(react): add the Menu primitive#23
Open
ivanbanov wants to merge 2 commits into
Open
Conversation
Menu / Trigger / Portal / Content / Item / Group / GroupLabel / Separator, shipped as an agnostic core machine (@dunky.dev/menu) plus a thin React binding (@dunky.dev/react-menu). A WAI-ARIA menu-button: arrow-key highlight with wrap, Home/End, typeahead, activedescendant focus, select-then-close items, and layer-stack-aware Escape/outside dismissal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Adds the Menu primitive as two packages:
@dunky.dev/menu(packages/core/menu) — the framework-free state machine: open/close (controlled and uncontrolled), item registry, single-value highlight, typeahead, and layer-stack-aware dismissal.@dunky.dev/react-menu(packages/react/menu) — the thin React binding: compound parts, portal rendering, focus management, anddata-statestyling hooks. No positioning engine; anchoring is the consumer's concern.A menu is a list of actions opened from a button: the user opens it, picks one action, and the menu goes away. It is non-modal and coexists with the page; every item is a command.
Note
This PR is stacked on the
feat/floatingextraction PR (shared overlay utilities) and targets that branch; it will retarget tomainoncefeat/floatingmerges.Anatomy
Behavior
aria-haspopup="menu"+aria-expanded; content isrole="menu"labelled by the trigger; items arerole="menuitem"; groups/role="group"labelled by their rendered GroupLabel; separators arerole="separator".aria-controlsonly references the content while it is rendered.aria-activedescendant: DOM focus stays on the content; the highlight is machine state, not roving focus. Disabled items are perceivable (aria-disabled) but never highlighted or activated.onOpenChange. A controlled menu never self-transitions — theopenprop drives it.Test plan
pnpm test:ci— 13 files, 182 tests passingpnpm typecheckpnpm lintpnpm format:checkpnpm build🤖 Generated with Claude Code