MenuItem

Overview

A menu item object is an individual item within a menu. It allows you to stylize and control the click behavior of the menu item. In addition its capabilities give access to providing application wide "hot keys" such as copy, and paste. MenuItem objects can only be appended to a Menu object.

Ancestors

  1. None
 

Descendants

  1. None
 

See Also

  1. Menu

Constructors

Description

Creates a new menuitem object.

Definition

new MenuItem(title, key, modifier)

Members

checked
Description

Gets or sets whether this menu item is "activated" or "highlighted" or "checked". This is expressed differently depending on the native OS, on most operating systems it shows a checkbox next to the menu item, on some operating systems it affects the background color and highlight. By default this is false.

Definition

boolean menuitem.checked (default false)
custom
Description

Gets or sets a custom control you'd like to place in the menu item. This is useful if you need to render more than just an icon or text in the menu item. It provides a way for users to enhance menu functionality. Any Control can be added and will have its width and height constrained to the system defined area, the layout will also be dictated by the operating system.

Definition

Control menuitem.custom
enabled
Description

Gets or sets whether the menu item is enabled or greyed out (disabled) Note that the item is still visible but does not respond to clicks and is visually denoted as inactive to the user. This is useful when you want to express that the choice or selection in the menu item is not available at the moment.

Definition

boolean menuitem.enabled
image
Description

Gets or sets the image that will be used for the menu item. This is placed as an icon next to menu items label. This can be any URL, including the app:// schema for referencing packaged resources, or it can be a named system icon resource.

Definition

string menuitem.image
key
Description

Gets or sets what key (in combination with modifiers), when pressed, activates this menu. This is useful when you want to provide a keyboard shortcut to a menu item so the user doesn't need to navigate or use their mouse (for instance, copy, or cmd/cntl+c would have 'c' for a key). Each menu item must have a unique key and modifier combination (if one in set). This is optional.

Definition

boolean menuitem.key
modifiers
Description

Gets or sets what modifiers (in combination with key), when pressed, activates this menu. This is useful when you want to provide a keyboard shortcut to a menu item so the user doesn't need to navigate or use their mouse (for instance, copy, or cmd/cntl+c would have 'c' for a key and 'cmd' for a modifier). Each menu item must have a unique key and modifier combination (if one in set). This is optional.

Definition

boolean menuitem.modifiers
Description

Gets or sets the submenu associated with this menu item. If the menu item has sub items or a sub-menu of its own it can be set here. This by default is not set and null.

Definition

Menu menuitem.submenu (default null)
title
Description

Gets or sets the text label used for this menu item.

Definition

string menuitem.title
tooltip
Description

Gets or sets the tooltip that is shown to the user if they hover over the menu item for more than a few seconds. This can be thought of as a description of what the menu item does. It shows as a fading in off-mouse window that lets the user know more about what the menu item does.

Definition

string menuitem.tooltip
visible
Description

Gets or sets whether the menu item is shown or hidden. The default is true.

Definition

boolean menuitem.visible (default true)

Methods

addEventListener(eventName, callback)
Description

Adds an event listener for various control level events. The first parameter is the name of the event, the second parameter is the function to call when the event happens (e.g., a callback).

Definition

menuitem.addEventListener(eventName, callback)
Parameters
NameTypeDescription
eventName string The name of the event to start listening to.
callback function The function that will be called when it occurs.
removeEventListener(eventName, callback)
Description

Removes an event listener for various application level events. The first parameter is the name of the event, the second parameter is the function that was originally given as the callback for addEventListener.

Definition

menuitem.removeEventListener(eventName, callback)
Parameters
NameTypeDescription
eventName string The name of the event to stop listening to.
callback function The function that would have been called.

Events

click
Description

Fires when the user clicks on the menu item or activates it with the keyboard shortcuts/arrows.

Definition

menuitem.addEventListener('click', function() { ... });