'How to make a Menu not close when a MenuItem's click event is invoked (Electron)
I have a simple Menu on a Tray application for electron.
I have a click option on my MenuItem and every time I click the menu item the menu closes. What can I do to make it stay?
I've read through this documentation: https://www.electronjs.org/docs/api/menu-item but can't seem to find the answer.
Supposedly the third argument to the click is a KeyboardEvent which extends Event which has a preventDefault on it, but if I try to invoke click: (item, menu, e) => { e.preventDefault(); } it throws an error saying e.preventDefault is not a function.
Hopefully i'm missing something simple, thanks in advance!
Here's what my menu looks like:
Menu.buildFromTemplate([
{
label: 'pls dont close',
click: (menuItem, window, e) => {
e.preventDefault();
}
},
{
label: 'Quit',
click: app.quit
}
])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
