From 64872a6cb8572f15af8a6ce43a6b6cb852195ec7 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 30 Jan 2026 10:07:16 +0100 Subject: [PATCH] fix: macOS menu item accelerators when item disabled (#49553) fix: macOS menu item acceerators when item disabled --- shell/browser/ui/cocoa/electron_menu_controller.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/browser/ui/cocoa/electron_menu_controller.mm b/shell/browser/ui/cocoa/electron_menu_controller.mm index 844ca12c31..94334af9c2 100644 --- a/shell/browser/ui/cocoa/electron_menu_controller.mm +++ b/shell/browser/ui/cocoa/electron_menu_controller.mm @@ -484,8 +484,11 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) { if (index < 0 || index >= count) return; + // When the menu is closed, we need to allow shortcuts to be triggered even + // if the menu item is disabled. So we only disable the menu item when the + // menu is open. This matches behavior of |validateUserInterfaceItem|. + item.enabled = model->IsEnabledAt(index) || !isMenuOpen_; item.hidden = !model->IsVisibleAt(index); - item.enabled = model->IsEnabledAt(index); item.state = model->IsItemCheckedAt(index) ? NSControlStateValueOn : NSControlStateValueOff; } @@ -567,18 +570,19 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) { if (!isMenuOpen_) return; - bool has_close_cb = !popupCloseCallback.is_null(); + isMenuOpen_ = NO; + [self refreshMenuTree:menu]; // There are two scenarios where we should emit menu-did-close: // 1. It's a popup and the top level menu is closed. // 2. It's an application menu, and the current menu's supermenu // is the top-level menu. + bool has_close_cb = !popupCloseCallback.is_null(); if (menu != menu_) { if (has_close_cb || menu.supermenu != menu_) return; } - isMenuOpen_ = NO; if (model_) model_->MenuWillClose(); // Post async task so that itemSelected runs before the close callback