Skip to content

Latest commit

 

History

History
103 lines (66 loc) · 3.03 KB

Documentation.md

File metadata and controls

103 lines (66 loc) · 3.03 KB

The jsMenus library

The demo.html shows most of these features.

The Menu class

Construction

new MenuItem(options)

Properties

These can be initialized in the options object passed to the constructor.

type - one of menubar or contextmenu (the default).

items - the array of MenuItems. You can also build this array incrementally using the append method.

beforeShow - a function that is called before the menu is displayed. This Menu is passed as the first argument. This is useful for updating properties of menu items. It can be used in place of the Electron menu-wil-show event. There is also a beforeShow call-back on MenuItem.

Class properties

contextMenuParent - Parent node for context menu popup. If null, document.body is the default.

Instance methods:

append(menuItem)

insert(item, index)

remove(item)

removeAt(index)

popup(clientX, clientY) - display this menu. This is normally only called directly for context menus.

Static methods

setApplicationMenu(menuBar)

The MenuItem class

Constructing

new MenuItem(options)

Properties

These can be initialized in the options object passed to the constructor.

type - one of separator, checkbox, radio, or normal (the default). If separator, this is not a real MenuItem, but is just used to display a separator line.

label - the descriptive label.

icon - an icon (small image) to display before the label.

submenu - a (child) sub-menu of the containing menu.

accelerator - keyboard accelerator. Usually a string representing a keyboard shortcut - for example "Ctrl+Shift+Q". A multi-key sequences (as used in Emacs) is represented as an array of strings - for example ["Ctrl+X", "B"]. (Alternatively, you can use a single string with spaces between each keystroke.) Using accelerator is preferred over using key and modifiers because it can handle multi-key sequences, and because this is compatible with Electron. Note this property is only "informational" - this library does not handle keyboard events, except for menu navigation.

key - keyboard key

modifiers - sequence of modifiers - used in conjuction with key. Displayed using symbols if MenuItem.useModifierSymbols is true, which is the default only on Mac.

enabled - normally true. If false, it is partially grayed out and cannot be selected.

visible - normally true. If false, it is hidden.

checked - true if a checkbox or radio item is selected. Clicking a checkbox item will toggle its checked field. Clicking a radio item will select the clicked field, and unselect any adjacent radio items in the same menu.

tooltip - a string displayed when hovering over the item.

click - function that gets called when selected (mouse click or keboard Enter). The active MenuItem is passed as the first arguemnt,

beforeShow - a function that is called before the MenuItem is displayed. It is useful for updating properties (such as checkboxes and visibility). This MenuItem is passed as the first argument.