#581

macOS: clicking a menu item that has a submenu closes the menu instead of opening the submenu

Openjyecuschopened 11d ago

Version: 2.0.4

Repro

Create a Tray and call setMenu with an item that has a submenu (no action). Open the tray menu and click the parent item instead of hovering it.

Expected

The submenu opens right away, or nothing happens (standard macOS behaviour).

Actual

The whole menu closes and tray-clicked fires with an empty action.

Cause

In package/src/native/macos/nativeWrapper.mm, createMenuFromConfig gives every item action:@selector(menuItemClicked:) (line 1281) and menuItem.target = target (line 1323), including parents. [menu setSubmenu:submenu forItem:menuItem] (line 1346) leaves both in place, so clicking a parent runs menuItemClicked: and the menu closes. setApplicationMenu and the context menu build their menus with the same function.

Suggested fix

When an item has a submenu, clear its action and target so AppKit handles the click by opening the submenu:

if (submenuConfig) {
  NSMenu *submenu = createMenuFromConfig(submenuConfig, target);
  [menu setSubmenu:submenu forItem:menuItem];
  menuItem.target = nil;
  menuItem.action = nil;
}

Activity

0

No activity yet.