Repository navigation
feat(desktop): add a reusable context menu provider - #182
Merged
dailker merged 1 commit intoDec 4, 2026
Merged
Conversation
ContextMenuProvider and useContextMenu() let any component open a right-click menu: rendered in a portal, flipped and clamped to stay on screen, closed on Esc, Tab, outside click, scroll, blur and resize, and navigable with the arrow keys, Home and End. Items take a label, icon, shortcut, disabled flag or a separator, styled with the theme's dropdown keys plus a new dropdown_item_focus key for the keyboard highlight. The desktop menu from codehubbers#93 becomes its first consumer and gains Next wallpaper and Settings. Refs codehubbers#94
Ziqian-Huang0607
approved these changes
Dec 4, 2026
Ziqian-Huang0607
left a comment
Member
There was a problem hiding this comment.
This is the right way to do #94: the service first, with the existing desktop menu as its first consumer rather than a parallel implementation.
What I verified:
- placeMenu flips and clamps correctly, and the unit tests cover the edge cases (right/bottom flip, clamping).
- The keyboard story is complete: Shift+F10 opens under the element when there is no pointer position, arrows wrap and skip disabled items and separators, Home/End jump, Esc/Tab close and restore focus. The screenshots show the edge flip working in a real browser.
- The measure-then-show pattern (hidden while measuring, focus after placement) is the correct fix for the focus-on-hidden-element trap, and the PR body is honest about catching it by hand outside jsdom.
- Theme integration is done properly: dropdown_item_focus added to all six themes, with a graceful fallback for themes without it, and the ThemeRegistry key-parity test passes.
- The desktop menu keeps its #93 behavior (desktopLayout tests untouched and green) and the new wallpaper/settings items reuse the same actions as the launcher.
- Ran locally on current main: ContextMenu, desktopLayout, i18n parity and ThemeRegistry suites, 76/76 green. CI green.
Good call splitting icon and File Manager menus into a second PR after #180, since both touch AppIcon.js.
Approve.
dailker
approved these changes
Dec 4, 2026
dailker
left a comment
Member
There was a problem hiding this comment.
Really solid first step for #94. The edge flip, focus handling and the extra theme key are all well done, and good catch on the hidden-while-measuring focus problem. One small thing for the follow-up PR: menu items use key={item.label}, so two items with the same label would collide. An index or an id would be safer. Go ahead with the app icon and File Manager menus now that #180 is in.
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.
Refs #94 (first of two PRs: provider + desktop menu here; the app icon and File Manager menus follow in a second PR, after #180 lands since it also touches
AppIcon.js).What and why
A reusable context menu service, as the issue describes, with the existing desktop menu from #93 as its first consumer instead of a second menu.
ContextMenuProvider+useContextMenu()(src/context/ContextMenuContext.js):openMenu(event, items, { label })prevents the browser menu, stops the event so the innermost element wins (an icon over the desktop, later), and renders the menu in a portal ondocument.body. Opened from the keyboard (Shift+F10 / the menu key, which report no pointer position), it opens under the element.ContextMenu(src/components/ContextMenu.js, renamed fromDesktopContextMenu.js): items are{ label, onClick, icon?, shortcut?, disabled? }or{ separator: true }.placeMenu, unit tested).role="menu"with anaria-label,role="menuitem"buttons,role="separator"; ↑ ↓ wrap and skip disabled items, Home/End jump; Enter/Space activate.theme.app.dropdown_bg,dropdown_item_hover, plus a newdropdown_item_focuskey in all six themes (the hover colours withfocus:), so the keyboard highlight matches the mouse one. Hovering an item also focuses it, so there's only ever one highlight. Themes without the new key still work.useDesktopLayoutactions,tests/desktopLayout.test.jsuntouched and passing), plus Next wallpaper (same cycling as the launcher command) and Settings. New keys are in all five locales.Left out for now, to keep this reviewable: submenus (and ← →), since no menu here needs one yet. The item shape leaves room for
submenuwhen the File Manager's "Open with…" needs it.How I tested it
tests/ContextMenu.test.js(12 tests): edge flip and clamping, browser menu prevented, label and theme classes, arrow/Home/End navigation skipping disabled items and separators, item runs and closes, disabled items don't run, Esc closes and restores focus, outside click / scroll / resize close, clicks inside keep it open, innermost element wins, clear error outside the provider.npm test(36 suites, 430 tests),npm run lint(0 errors, only the existing warnings),npx prettier --checkon the changed files andnpm run buildall pass.npm run dev, Local Admin, 1280×800): the steps below. Doing this caught one thing jsdom didn't: the menu is hidden while it's measured, and a hidden element can't take focus, so focus now moves to the first item once it's placed, and the keys are read on the window.Keyboard-only steps
Screenshots
Desktop menu, keyboard focus on "Next wallpaper" (same highlight as hover):
Right-click near the bottom-right corner: the menu flips up and left to stay on screen:
After End, ↑, Enter on "Next wallpaper":
Checklist
type(scope): summary, for examplefix(calculator): keep history after reloadnpm testpassesnpx prettier --checkpasses on the files I changed