Header menu logo fable-electron-docs-api

Menu Type

⚠ Process Availability: Main ✔ | Renderer ❌ | Utility ❌ | Exported ✔### Class: Menu> Create native application menus and context menus.Process: Main> [!TIP] See also: A detailed guide about how to implement menus in your application.> [!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.

Constructors

Constructor Description

Menu()

Full Usage: Menu()

Returns: Menu
Returns: Menu

Instance members

Instance member Description

this.append menuItem

Full Usage: this.append menuItem

Parameters:
Modifiers: inline

Appends the menuItem to the menu.

menuItem : MenuItem

this.closePopup ?window

Full Usage: this.closePopup ?window

Parameters:
Modifiers: inline

Closes the context menu in the window.

?window : BaseWindow

this.getMenuItemById id

Full Usage: this.getMenuItemById id

Parameters:
    id : string

Returns: Option<MenuItem>
Modifiers: inline

the item with the specified id

id : string
Returns: Option<MenuItem>

this.insert (pos, menuItem)

Full Usage: this.insert (pos, menuItem)

Parameters:
Modifiers: inline

Inserts the menuItem to the pos position of the menu.

pos : int
menuItem : MenuItem

this.items

Full Usage: this.items

A MenuItem[] array containing the menu's items.Each Menu consists of multiple MenuItem instances and each MenuItem can nest a Menu into its submenu property.

this.offMenuWillClose handler

Full Usage: this.offMenuWillClose handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when a popup is closed either manually or with menu.closePopup().

handler : Event -> unit

this.offMenuWillShow handler

Full Usage: this.offMenuWillShow handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when menu.popup() is called.

handler : Event -> unit

this.onMenuWillClose handler

Full Usage: this.onMenuWillClose handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when a popup is closed either manually or with menu.closePopup().

handler : Event -> unit

this.onMenuWillShow handler

Full Usage: this.onMenuWillShow handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when menu.popup() is called.

handler : Event -> unit

this.onceMenuWillClose handler

Full Usage: this.onceMenuWillClose handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when a popup is closed either manually or with menu.closePopup().

handler : Event -> unit

this.onceMenuWillShow handler

Full Usage: this.onceMenuWillShow handler

Parameters:
    handler : Event -> unit

Modifiers: inline

Emitted when menu.popup() is called.

handler : Event -> unit

this.popup (?window, ?frame, ?x, ?y, ?positioningItem, ?sourceType, ?callback)

Full Usage: this.popup (?window, ?frame, ?x, ?y, ?positioningItem, ?sourceType, ?callback)

Parameters:
Modifiers: inline

Pops up this menu as a context menu in the BaseWindow.> [!TIP] For more details, see the Context Menu guide.

?window : BaseWindow
?frame : WebFrameMain
?x : float
?y : float
?positioningItem : float
?sourceType : SourceType
?callback : unit -> unit

Static members

Static member Description

Menu.buildFromTemplate template

Full Usage: Menu.buildFromTemplate template

Parameters:
Returns: Menu
Modifiers: inline

Generally, the template is an array of options for constructing a MenuItem. The usage can be referenced above.You can also attach other fields to the element of the template and they will become properties of the constructed menu items.

template : U2<Options, MenuItem>[]
Returns: Menu

Menu.getApplicationMenu ()

Full Usage: Menu.getApplicationMenu ()

Returns: Option<Menu>
Modifiers: inline

The application menu, if set, or null, if not set.> [!NOTE] The returned Menu instance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.

Returns: Option<Menu>

Menu.sendActionToFirstResponder action

Full Usage: Menu.sendActionToFirstResponder action

Parameters:
    action : string

Modifiers: inline

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌

Sends the action to the first responder of application. This is used for emulating default macOS menu behaviors. Usually you would use the role property of a MenuItem.See the macOS Cocoa Event Handling Guide for more information on macOS' native actions.

action : string

Menu.setApplicationMenu menu

Full Usage: Menu.setApplicationMenu menu

Parameters:
Modifiers: inline

Sets menu as the application menu on macOS. On Windows and Linux, the menu will be set as each window's top menu.Also on Windows and Linux, you can use a & in the top-level item name to indicate which letter should get a generated accelerator. For example, using &File for the file menu would result in a generated Alt-F accelerator that opens the associated menu. The indicated character in the button label then gets an underline, and the & character is not displayed on the button label.In order to escape the & character in an item name, add a proceeding &. For example, &&File would result in &File displayed on the button label.Passing null will suppress the default menu. On Windows and Linux, this has the additional effect of removing the menu bar from the window.> [!NOTE] The default menu will be created automatically if the app does not set one. It contains standard items such as File, Edit, View, Window and Help.

menu : Option<Menu>

Type something to start searching.