Repository navigation
core: Close an open menu on a secondary click outside it without opening another - #4221
Conversation
…ing another A secondary click outside an open menu (any overlay listening to onPressOutside) now only closes it, on macOS, Linux and Windows: it opens neither the app's onContextMenu menu nor a platform menu (a text field's, selectable text's edit menu). Agent: lead Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s menu
A Popover with closeOnPressOutside={false} still hears onPressOutside (it
reports a cancel), but a press outside leaves it open: a secondary click
outside it now goes on to the menu it asks for instead of only closing
overlays that do not close. Fixes the compat case base-popups-desktop.
Agent: lead
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed b393966 to fix the Cause: the case keeps a Fix: such a popover now marks its overlay as staying open (an internal, Local (Windows): nsh-core overlay/context-menu tests and |
|
💡 Consistent implementation, but it reverses #1610: a secondary click outside an open menu now only closes it instead of also opening the new context menu, unlike macOS native behaviour.
Reviewed at b393966. |
Description
While a menu, popover or any overlay listening to
onPressOutsideis open, a primary click outside it closes it, but a right click did not behave the same way:onContextMenulistener, or on selectable text or a text field, the platform got no press at all: the open menu stayed up and the platform's own edit menu could open on top of it, leaving two menus.onContextMenu, the menu closed and a new one opened at once (behavior added in menu: ReopenContextMenuwhere its trigger is right-clicked again #1610).A secondary click outside an open menu now only closes it. It opens no other menu, neither the app's nor the platform's. The next right click works as usual. A right click inside the overlay is not affected.
How
nsh-core): while an overlay that listens toonPressOutsideis shown, the root view it is shown in also getsonPressOutsideamong its mounted events. This is an internal marker that lets the platform know a press-outside overlay is open in that window.nsh_core::input::context_menu_target: if the root hop has that marker and no inner hop listens toonPressOutside(the click is outside every such overlay), it returns the newContextMenuTarget::Dismiss(root).Dismiss, they skip the app, field, edit-menu and text-link menus and report the click as a context menu on the root view.onPressOutsideevents, they are handed out andonContextMenuis not dispatched. This reverses the "close and reopen at the pointer" part of menu: ReopenContextMenuwhere its trigger is right-clicked again #1610 (the controlled-openfix inpopup.rsfrom that PR is kept).rightClickpicks targets with the same rule, so app tests behave like the desktops.Public API
No new app-facing API.
ContextMenuHopgains apress_outsidefield andContextMenuTargetgains aDismissvariant. Both live innsh_core::inputand are used by the platform crates only.Behavior change:
ContextMenu's docs now say that a secondary click outside an open menu, whether on its trigger or anywhere else, only closes it.How to Test
cargo test -p nsh-core --lib: all 2160 pass. New tests:input::tests::a_secondary_click_outside_an_open_menu_only_closes_itcore::tests::the_root_view_of_an_overlay_watching_presses_tells_its_platform_viewcargo test -p nsh-base --test base: all 1345 pass.a_secondary_click_on_the_trigger_of_an_open_context_menu_only_closes_itreplaces the reopen test.cargo test -p nsh-testing --features bundle --test testing -- a_press_tells_an_overlay: the new TSX case checks that a right click on a row withonContextMenuwhile an overlay is open tells the overlayonPressOutsideand calls noonContextMenu.cargo test -p nsh-engine --test engine -- --skip websocket: all 493 pass. The websocket tests fail in this sandbox because they need loopback networking.examples/gallery/tests/context-menu-reopen.test.tsxis updated to the new behavior. I did not run it locally.Not verified: I built and tested this on Linux only. The macOS and Windows platform changes were not compiled locally and rely on CI. I have not checked this in a real window on any platform yet, including a native text field's own menu on macOS, which AppKit may show before NSH sees the click.
🤖 Generated with Claude Code
🤖 Noop (lead) · Opus 5.5 acting for @huacnlee