Header menu logo fable-electron-docs-api

MenuItem Type

⚠ Process Availability: Main ✔ | Renderer ❌ | Utility ❌ | Exported ✔### Class: MenuItem> Add items to native application menus and context menus.Process: MainSee Menu for examples.> [!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.

Constructors

Constructor Description

MenuItem(?click, ?role, ?type, ?label, ?sublabel, ?toolTip, ?accelerator, ?icon, ?enabled, ?acceleratorWorksWhenHidden, ?visible, ?checked, ?registerAccelerator, ?sharingItem, ?submenu, ?id, ?before, ?after, ?beforeGroupContaining, ?afterGroupContaining)

Full Usage: MenuItem(?click, ?role, ?type, ?label, ?sublabel, ?toolTip, ?accelerator, ?icon, ?enabled, ?acceleratorWorksWhenHidden, ?visible, ?checked, ?registerAccelerator, ?sharingItem, ?submenu, ?id, ?before, ?after, ?beforeGroupContaining, ?afterGroupContaining)

Parameters:
    ?click : MenuItem * Option<BaseWindow> * KeyboardEvent -> unit - Will be called with click(menuItem, window, event) when the menu item is clicked.
    ?role : Role - 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, showSubstitutions, toggleSmartQuotes, toggleSmartDashes, toggleTextReplacement, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow or windowMenu - Define the action of the menu item, when specified the click property will be ignored. See roles.
    ?type : Type -
    ?label : string -
    ?sublabel : string - ⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Available in macOS >= 14.4
    ?toolTip : string - ⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Hover text for this menu item.
    ?accelerator : string - An Accelerator string.
    ?icon : U2<NativeImage, string> -
    ?enabled : bool - If false, the menu item will be greyed out and unclickable.
    ?acceleratorWorksWhenHidden : bool - ⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || default is true, and when false will prevent the accelerator from triggering the item if the item is not visible.
    ?visible : bool - If false, the menu item will be entirely hidden.
    ?checked : bool - Should only be specified for checkbox or radio type menu items.
    ?registerAccelerator : bool - ⚠ OS Compatibility: WIN ✔ | MAC ❌ | LIN ✔ | MAS ❌ || If false, the accelerator won't be registered with the system, but it will still be displayed. Defaults to true.
    ?sharingItem : SharingItem - ⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || The item to share when the role is shareMenu.
    ?submenu : U2<Options[], Menu> - Should be specified for submenu type menu items. If submenu is specified, the type: 'submenu' can be omitted. If the value is not a Menu then it will be automatically converted to one using Menu.buildFromTemplate.
    ?id : string - Unique within a single menu. If defined then it can be used as a reference to this item by the position attribute.
    ?before : string[] - Inserts this item before the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu. Also implies that the menu item in question should be placed in the same “group” as the item.
    ?after : string[] - Inserts this item after the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu.
    ?beforeGroupContaining : string[] - Provides a means for a single context menu to declare the placement of their containing group before the containing group of the item with the specified id.
    ?afterGroupContaining : string[] - Provides a means for a single context menu to declare the placement of their containing group after the containing group of the item with the specified id.

Returns: MenuItem
?click : MenuItem * Option<BaseWindow> * KeyboardEvent -> unit

Will be called with click(menuItem, window, event) when the menu item is clicked.

?role : Role

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, showSubstitutions, toggleSmartQuotes, toggleSmartDashes, toggleTextReplacement, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow or windowMenu - Define the action of the menu item, when specified the click property will be ignored. See roles.

?type : Type

?label : string

?sublabel : string

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Available in macOS >= 14.4

?toolTip : string

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Hover text for this menu item.

?accelerator : string

An Accelerator string.

?icon : U2<NativeImage, string>

?enabled : bool

If false, the menu item will be greyed out and unclickable.

?acceleratorWorksWhenHidden : bool

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || default is true, and when false will prevent the accelerator from triggering the item if the item is not visible.

?visible : bool

If false, the menu item will be entirely hidden.

?checked : bool

Should only be specified for checkbox or radio type menu items.

?registerAccelerator : bool

⚠ OS Compatibility: WIN ✔ | MAC ❌ | LIN ✔ | MAS ❌ || If false, the accelerator won't be registered with the system, but it will still be displayed. Defaults to true.

?sharingItem : SharingItem

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || The item to share when the role is shareMenu.

?submenu : U2<Options[], Menu>

Should be specified for submenu type menu items. If submenu is specified, the type: 'submenu' can be omitted. If the value is not a Menu then it will be automatically converted to one using Menu.buildFromTemplate.

?id : string

Unique within a single menu. If defined then it can be used as a reference to this item by the position attribute.

?before : string[]

Inserts this item before the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu. Also implies that the menu item in question should be placed in the same “group” as the item.

?after : string[]

Inserts this item after the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu.

?beforeGroupContaining : string[]

Provides a means for a single context menu to declare the placement of their containing group before the containing group of the item with the specified id.

?afterGroupContaining : string[]

Provides a means for a single context menu to declare the placement of their containing group after the containing group of the item with the specified id.

Returns: MenuItem

Instance members

Instance member Description

this.accelerator

Full Usage: this.accelerator

An Accelerator (optional) indicating the item's accelerator, if set.

this.checked

Full Usage: this.checked

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.You can add a click function for additional behavior.

this.click

Full Usage: this.click

A Function that is fired when the MenuItem receives a click event. It can be called with menuItem.click(event, focusedWindow, focusedWebContents).* event KeyboardEvent* focusedWindow BaseWindow* focusedWebContents WebContents

this.commandId

Full Usage: this.commandId

A number indicating an item's sequential unique id.

this.enabled

Full Usage: this.enabled

A boolean indicating whether the item is enabled. This property can be dynamically changed.

this.icon

Full Usage: this.icon

A NativeImage | string (optional) indicating the item's icon, if set.

this.id

Full Usage: this.id

A string indicating the item's unique id. This property can be dynamically changed.

this.label

Full Usage: this.label

A string indicating the item's visible label.

this.menu

Full Usage: this.menu

A Menu that the item is a part of.

this.registerAccelerator

Full Usage: this.registerAccelerator

A boolean indicating if the accelerator should be registered with the system or just displayed.This property can be dynamically changed.

this.role

Full Usage: this.role

A string (optional) 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

this.sharingItem

Full Usage: this.sharingItem

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ A SharingItem indicating the item to share when the role is shareMenu.This property can be dynamically changed.

this.sublabel

Full Usage: this.sublabel

A string indicating the item's sublabel.

this.submenu

Full Usage: this.submenu

A Menu (optional) containing the menu item's submenu, if present.

this.toolTip

Full Usage: this.toolTip

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ A string indicating the item's hover text.

this.type

Full Usage: this.type

A string indicating the type of the item. Can be normal, separator, submenu, checkbox, radio, header or palette.> [!NOTE] header and palette are only available on macOS 14 and up.

this.userAccelerator

Full Usage: this.userAccelerator

Returns: Option<Accelerator>

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ An Accelerator | null indicating the item's user-assigned accelerator for the menu item.> [!NOTE] 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 just return null.

Returns: Option<Accelerator>

this.visible

Full Usage: this.visible

A boolean indicating whether the item is visible. This property can be dynamically changed.

Type something to start searching.