MenuItem constructor options - click callback
The click option is an optional function called when the menu item is clicked. It receives three parameters: menuItem (MenuItem), window (BaseWindow | undefined, undefined if no window is open), and event (KeyboardEvent).
MenuItem role values
The role option can be one of: undo, redo, cut, copy, paste, pasteAndMatchStyle, delete, selectAll, reload, forceReload, toggleDevTools, resetZoom, zoomIn, zoomOut, toggleSpellChecker, togglefullscreen, window, minimize, close, help, about, services, hide, hideOthers, unhide, quit, showSubstitutions, toggleSmartQuotes, toggleSmartDashes, toggleTextReplacement, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow, or windowMenu. When role is specified, the click property will be ignored.
MenuItem type values
The type option can be: normal, separator, submenu, checkbox, radio, header (macOS 14 and up only), or palette (macOS 14 and up only).
MenuItem constructor options - full reference
MenuItem constructor accepts an options object with: click (Function, optional), role (string, optional), type (string, optional), label (string, optional), accessibilityLabel (string, optional, macOS only), sublabel (string, optional, macOS >= 14.4), toolTip (string, optional, macOS only), accelerator (string, optional), icon (NativeImage | string, optional), enabled (boolean, optional), acceleratorWorksWhenHidden (boolean, optional, macOS, default true), visible (boolean, optional), checked (boolean, optional), registerAccelerator (boolean, optional, Linux/Windows, defaults to true), sharingItem (SharingItem, optional, macOS), submenu (MenuItemConstructorOptions[] | Menu, optional), id (string, optional, unique within single menu), before (string[], optional), after (string[], optional), beforeGroupContaining (string[], optional), afterGroupContaining (string[], optional), badge (MenuItemBadge, optional, macOS 14 and up).
acceleratorWorksWhenHidden behavior on different platforms
The acceleratorWorksWhenHidden option is macOS-specific with a default of true. Accelerators always work when items are hidden on Windows and Linux. On macOS, setting acceleratorWorksWhenHidden to false will prevent the accelerator from triggering the item if the item is not visible.
MenuItem.id property
The id property is a string indicating the item's unique id within a single menu. This property can be dynamically changed.
MenuItem.label property
The label property is a string indicating the item's visible label. This property can be dynamically changed.
MenuItem.accessibilityLabel property
The accessibilityLabel property is a string (macOS only) indicating the item's accessibility label used by assistive technology, if set. This property can be dynamically changed.
MenuItem.click method
The click property is a function that is fired when the MenuItem receives a click event. It can be called with menuItem.click(event, focusedWindow, focusedWebContents) where event is a KeyboardEvent, focusedWindow is a BaseWindow, and focusedWebContents is a WebContents.
MenuItem.submenu property
The submenu property is an optional Menu containing the menu item's submenu, if present.
MenuItem.type property
The type property is a string indicating the type of the item. Can be normal, separator, submenu, checkbox, radio, header, or palette. The header and palette types are only available on macOS 14 and up.
MenuItem.role property
The role property is an optional string indicating the item's role if set. Can be: undo, redo, cut, copy, paste, pasteAndMatchStyle, delete, selectAll, reload, forceReload, toggleDevTools, resetZoom, zoomIn, zoomOut, toggleSpellChecker, togglefullscreen, window, minimize, close, help, about, services, hide, hideOthers, unhide, quit, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow, or windowMenu.
MenuItem.accelerator property
The accelerator property is an Accelerator | null indicating the item's accelerator, if set.
MenuItem.userAccelerator property
The userAccelerator property is readonly and macOS-only. It is an Accelerator | null indicating the item's user-assigned accelerator. This property is only initialized after the MenuItem has been added to a Menu, either via Menu.buildFromTemplate or via Menu.append()/insert(). Accessing before initialization will return null.
MenuItem.icon property
The icon property is a NativeImage | string (optional) indicating the item's icon, if set. This property can be dynamically changed.
MenuItem.sublabel property
The sublabel property is a string indicating the item's sublabel. This property can be dynamically changed.
MenuItem.toolTip property
The toolTip property is a string (macOS only) indicating the item's hover text.
MenuItem.enabled property
The enabled property is a boolean indicating whether the item is enabled. When false, the menu item will be greyed out and unclickable. This property can be dynamically changed.
MenuItem.visible property
The visible property is a boolean indicating whether the item is visible. When false, the menu item will be entirely hidden. This property can be dynamically changed.
MenuItem.checked property behavior
The checked property is a boolean indicating whether the item is checked. This property can be dynamically changed. A checkbox menu item will toggle the checked property on and off when selected. A radio menu item will turn on its checked property when clicked and will turn off that property for all adjacent items in the same menu. A click function can be added for additional behavior.
MenuItem.registerAccelerator property
The registerAccelerator property is a boolean (Linux/Windows only) indicating if the accelerator should be registered with the system or just displayed. This property can be dynamically changed.
MenuItem.sharingItem property
The sharingItem property is a SharingItem (macOS only) indicating the item to share when the role is shareMenu. This property can be dynamically changed.
MenuItem.commandId property
The commandId property is a number indicating an item's sequential unique id.
MenuItem.menu property
The menu property is a Menu that the item is a part of.
MenuItem.badge property
The badge property is a MenuItemBadge (optional, macOS 14 and up only) indicating the badge for the menu item. This property can be dynamically changed; setting it to undefined removes the badge.