Skip to content

Offer the host's action menu to plugins - #4270

Merged
gilgtm merged 3 commits into
mainfrom
plugin-ui-menu
Nov 23, 2026
Merged

gilgtm merged 3 commits into
mainfrom
plugin-ui-menu

Conversation

@gilgtm

@gilgtm gilgtm commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Plugins can now open a real host action menu. ctx.reflect.get("ui").Menu takes a trigger and a list of items, and the host owns everything else: the popup that escapes clipping containers, hover highlight, arrow keys, typeahead, Escape, focus return, and the red destructive tone. Before this, a plugin that wanted a "⋯" menu had to build its own, and it got clipped, missed keyboard support, or looked different from the app's menus.

The contract stays narrow. Items are { label, onSelect, tone?: "default" | "destructive", disabled? }, with no submenus, checkboxes, radios or separators. ui.Menu is optional in the type, so plugins check for it and fall back on older hosts.

flowchart LR
  P[Plugin] -->|"ctx.reflect.get('ui')"| U{ui.Menu?}
  U -->|missing: older host| F[Plugin's own fallback]
  U -->|present| M["ui.Menu({ aria-label or label, items })"]
  M --> H[Host Menu: portal above clipping containers,<br/>highlight, arrows, typeahead, Escape, focus return]
  H -->|user picks an item| S["item.onSelect()"]
  S -->|optional| D[ui.Dialog opens]
Loading

Screenshots

The examples/plugins/host-controls plugin in the packaged macOS app, with the destructive "Clear name" item under the pointer.

Light Dark
Destructive item highlighted, light mode Destructive item highlighted, dark mode

Video

Narrated runs in the packaged app, driven with the real pointer and real keys. They cover click to open, hover, a disabled item, keyboard open, arrows and Escape, the destructive item, and "Edit name" opening a Dialog with focus returning to the trigger.

Light mode:

plugin-menu-light-20261123-181158-annotated.mp4

Dark mode:

plugin-menu-dark-20261123-181749-annotated.mp4

How it works

  • src/features/plugin-ui/contract.ts adds PluginMenuItem and PluginMenuProps. PluginUi.Menu is optional so authors must feature-detect it.
  • src/features/plugin-ui/service.tsx maps the contract onto the shared Menu (Base UI). Without a label, the trigger is an IconButton with the More icon and the aria-label as its name and tooltip. With a label, it is a ghost Button. tone: "destructive" maps to the host's danger tone.
  • Plain-JS values of the wrong type are treated as absent, like the other controls: a non-element icon, a non-string label, or a non-function onSelect is ignored, and items without a string label are dropped.
  • src/plugins/author.ts exports the new types. The example plugin, the authoring guide and the examples README show the menu.

Testing

  • src/features/plugin-ui/service.test.tsx covers the keyboard path (Enter, arrows, typeahead, disabled item, Enter to select, focus return), the menu rendering outside a clipping card, and a destructive item that opens a Dialog with Escape returning focus to the trigger. The wrong-type test now includes a Menu.
  • src/plugins/author.test.mjs checks that authors must guard ui.Menu before using it.
  • Manual: the videos above, recorded with the example plugin installed from a local folder into a packaged debug build against a local relay.

Risk

Low. The change is additive to the plugin UI service. Existing controls and host menus are untouched, and older plugins do not see a difference.

Known limits

  • Typeahead is not shown in the videos, because the native driver only sends named keys. The unit test covers it.
  • Item labels must be unique within a menu; they are the React keys and the typeahead text.
  • A plain-JS plugin that passes neither label nor aria-label gets a trigger with no accessible name. TypeScript authors cannot do this.

🤖 Generated with Claude Code

gilgtm and others added 3 commits November 23, 2026 11:10
Adds Menu to the optional ui service: a host-rendered trigger (label or
icon button) and plain items with label, onSelect, destructive tone and
disabled. The host owns the portal, highlight, keyboard, typeahead,
Escape and focus return. Menu is optional in the type so plugins check
ui.Menu on hosts from before it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gil Birman <gil@squareup.com>
Prove arrow keys and typeahead move focus, and that a disabled item does nothing. Validated with vitest src/features/plugin-ui and a disabled-item mutation check.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gil Birman <gil@squareup.com>
Drop the redundant MenuItem label; Base UI types ahead on the item's text. Validated with vitest src/features/plugin-ui.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gil Birman <gil@squareup.com>
@gilgtm
gilgtm marked this pull request as ready for review November 23, 2026 18:43
@gilgtm
gilgtm requested a review from a team as a code owner November 23, 2026 18:43

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Star Lord. Ready for approval at c5b473d. The optional action menu fits the existing plugin UI service, and the source review found no changes needed. Required CI passed in the review snapshot. Runtime behavior was not independently exercised.

@dr0uleau dr0uleau 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.

🤖 reviewed at c5b473dc -- optional plugin menu capability, no existing host UX change. CI passed and no actionable findings remain

@dr0uleau
dr0uleau requested a review from a team November 23, 2026 19:00
@gilgtm
gilgtm merged commit 66c8cd3 into main Nov 23, 2026
53 checks passed
@gilgtm
gilgtm deleted the plugin-ui-menu branch November 23, 2026 19:00
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.

3 participants