Skip to content

Add a right-click menu to sites in the sidebar - #686

Open
amitraj2203 wants to merge 2 commits into
WordPress:trunkfrom
amitraj2203:feature/666-sidebar-context-menu
Open

amitraj2203 wants to merge 2 commits into
WordPress:trunkfrom
amitraj2203:feature/666-sidebar-context-menu

Conversation

@amitraj2203

Copy link
Copy Markdown
Contributor

Why

A site in the sidebar offers no actions of its own: the only menu is in the page header, and that acts on whichever site is open, not the one a contributor is pointing at. Users right-click a sidebar entry expecting the same menu the header offers (#666).

What changes

Right-clicking a site's row in the sidebar, or pressing Shift+F10 or the Menu key while it has focus, opens the same "Site actions" menu the page header already has, scoped to that row's site and without changing which site is open. The menu's contents are shared with the header button through one SiteMenuItems rendering, so the two offer the same actions in the same order and stay in sync automatically.

How to test this

Starting state:

  1. Launch the app with at least two sites, one of them open.
  2. Right-click a site in the sidebar that is not the one currently open.

What must not have happened:

  • The open site must not change: its page, header and aria-pressed state stay as they were.
  • The action chosen from the menu must act on the right-clicked site, not the open one (try "Copy path" and confirm the copied path is the inactive site's).
  • Dismissing the menu (Escape, or clicking outside) returns keyboard focus to the row that was right-clicked.
  • The same menu opens with Shift+F10 or the Menu key on a focused row, and Escape closes it the same way.

Covered by a new e2e journey, tests/e2e/journeys/shell.spec.js:110, and a new unit test for the anchor-position arithmetic, tests/unit/context-menu-position.test.cjs.

Risks and limitations

None known. No new IPC surface, no new dependency, no platform-specific gap.

Related

Fixes #666


Design decisions and alternatives considered

The context menu reuses the existing header menu's model (siteMenuItems) and rendering (SiteMenuItems) rather than a second implementation, so the two can't drift out of sync. The anchor is a fixed, invisible trigger button positioned at the requested point, since the menu library needs a real trigger element to anchor and manage focus around; the actual control the contributor presses stays the site's row.

The anchor-position arithmetic (a real pointer event's own point, or the pressed row's centre for a keyboard-triggered request) was split into its own pure module, src/renderer/context-menu-position.cjs, because index.jsx cannot be loaded without a DOM and nothing in node --test could otherwise reach it.

Review outcome (required — see AGENTS.md)
  • Review: completed — self-review (fresh context, per .agents/skills/self-review/SKILL.md), against .github/instructions/code-review.instructions.md; reviewed working-tree diff on feature/666-sidebar-context-menu vs base trunk at 60078fe. 2 findings, both fixed: branching position logic moved out of the component into context-menu-position.cjs with its own unit test, and a bug where a real pointer event's clientX/clientY of 0 was mistaken for a missing one (now told apart by the event's type instead).
  • Since review: none.
Implementation notes
  • sites-sidebar.jsx keys off .dataviews-view-list__item-wrapper, a class from @wordpress/dataviews's own list-layout source. It is undocumented as a public contract, but a future rename there just no-ops the context menu (the closest() lookup fails silently) rather than throwing.

A site in the sidebar offered no actions of its own: the only menu was
in the page header, and that acted on whichever site was open, not the
one being pointed at (WordPress#666). Right-clicking a site's row, or pressing
Shift+F10 or the Menu key on it, now opens the same Site actions menu,
scoped to that row's site and without changing which site is open.

The menu's contents are shared with the header button through one
SiteMenuItems rendering, so the two stay in sync automatically. The
anchor position is resolved by a small pure function split into its
own module, since index.jsx cannot be loaded without a DOM and nothing
in node --test could otherwise reach it.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ryanwelcher

Copy link
Copy Markdown
Collaborator

@amitraj2203 is the ready for review?

@amitraj2203

Copy link
Copy Markdown
Contributor Author

@ryanwelcher Yes

@amitraj2203
amitraj2203 marked this pull request as ready for review October 20, 2026 15:49
@ryanwelcher
ryanwelcher requested a review from zaerl October 20, 2026 18:07

@zaerl zaerl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is great work.

@amitraj2203 @ryanwelcher I will only add a minor optimization here:

If a user right-clicks a sidebar entry different from the current one and selects "Update to latest trunk" the selected entry should change to that one in order to show the user the loading box in the main column.

Otherwise, it seems nothing is happening. What do you think?

Image

Update to latest trunk's progress only renders on the active site, so
choosing it from a different row's context menu ran the update with
nothing visible for it (WordPress#666 review). That action now opens the site
it targets first, while every other action in the menu keeps acting
on the right-clicked site without opening it.
@amitraj2203

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I have made the changes

@zaerl

zaerl commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

@ryanwelcher, can you please remove me as a reviewer from the PRs in this repository? I've removed myself as an admin. When you have time, thanks.

This branch has not been deployed

No deployments
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.

Add right-click menu in on left sidebar

3 participants