electron: Menu enabled/visible property doesn't affect top-level menu items
- Electron version: 1.4.15
- Operating system: macOS Sierra, Windows 10
Expected behavior
Top level menu items should be hidden when the visible property is false and not be clickable when enabled property is false.
Actual behavior
The visible and enabled properties do not behave correctly on top level menu items. It seems to work correctly for submenu items.
How to reproduce
Create a menu with this code:
const { Menu } = require('electron').remote;
const template = [
{
label: 'Should not be visible',
visible: false,
submenu: [
{
label: 'Should not be visible either',
visible: false
}
]
},
{
label: 'Should not be enabled',
enabled: false,
submenu: [
{
label: 'Should not be enabled either',
enabled: false
}
]
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
Both menu items will still be visible and clickable.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 19 (9 by maintainers)
Hi all, i had some time to circle back to this.
When MacOS is deciding how to render a given item, it is validated (determined to be enabled/disabled, visible/invisible, checked, etc) with a method called
validateUserInterfaceItem. This method is always invoked just before a menu is displayed; however, top level menu items are rendered before this validation occurs and therefore are not able to respect these properties in the way that submenu items are.I won’t say it’d be 100% impossible for this to ever work, but our current architecture precludes it, and therefore i’m labeling it a
wontfix.@sindresorhus you’re right, i’ll put up a PR for that today.
@zecoo it’s always existed, since the menu api was first implemented; see my above comment
It seems to still exist in Electron 3.0.0
I can confirm this still exists in Electron 2.0.4