class sap.ui.unified.Menu

Control sample: sap.ui.unified.Menu
Visiblity: public
UX Guidelines:
Implements: sap.ui.core.IContextMenu
Available since: N/A
Module: sap/ui/unified/Menu
Application Component: CA-UI5-CTR

A menu is an interactive element which provides a choice of different actions to the user. These actions (items) can also be organized in submenus. Like other dialog-like controls, the menu is not rendered within the control hierarchy. Instead it can be opened at a specified position via a function call.


Constructor

Constructor for a new Menu control.

Accepts an object literal mSettings that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject#constructor for a general description of the syntax of the settings object.

new sap.ui.unified.Menu(sId?, mSettings?)
Param Type Default Value Description
sId? string

Id for the new control, generated automatically if no id is given

mSettings? object

Initial settings for the new control


Properties

Name Type Default Value Description
ariaDescription string

Accessible label / description of the menu for assistive technologies like screenreaders.

Visibility: public
enabled boolean true

When a menu is disabled none of its items can be selected by the user. The enabled property of an item (@link sap.ui.unified.MenuItemBase#getEnabled) has no effect when the menu of the item is disabled.

Visibility: public
maxVisibleItems int 0

The maximum number of items which are displayed before an overflow mechanism takes effect. A value smaller than 1 means an infinite number of visible items. The overall height of the menu is limited by the height of the screen. If the maximum possible height is reached, an overflow takes effect, even if the maximum number of visible items is not yet reached.

Visibility: public
pageSize int 5

The keyboard can be used to navigate through the items of a menu. Beside the arrow keys for single steps and the Home / End keys for jumping to the first / last item, the Page Up / Page Down keys can be used to jump an arbitrary number of items up or down. This number can be defined via the pageSize property. For values smaller than 1, paging behaves in a similar way to when using the Home / End keys. If the value equals 1, the paging behavior is similar to that of the arrow keys.

Since: 1.25.0.

Visibility: public

Aggregations

Default Aggregation: items

Name Cardinality Type Description
items (default) 0..n sap.ui.unified.MenuItemBase

The available actions to be displayed as items of the menu.


Associations

Name Cardinality Type Description
ariaLabelledBy 0..n sap.ui.core.Control

Reference to accessible labels (ids of existing DOM elements or controls) for assistive technologies like screenreaders.

Since: 1.26.3.


Events Overview

Event Description
itemSelect

Fired on the root menu of a menu hierarchy whenever a user selects an item within the menu or within one of its direct or indirect submenus. Note: There is also a select event available for each single menu item. This event and the event of the menu items are redundant.

itemSelect

Fired on the root menu of a menu hierarchy whenever a user selects an item within the menu or within one of its direct or indirect submenus. Note: There is also a select event available for each single menu item. This event and the event of the menu items are redundant.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object
item sap.ui.unified.MenuItemBase

The action (item) which was selected by the user.


Methods Overview

Method Description
addAriaLabelledBy

Adds some ariaLabelledBy into the association ariaLabelledBy.

addItem

Adds some item to the aggregation items.

attachItemSelect

Attaches event handler fnFunction to the itemSelect event of this sap.ui.unified.Menu.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.unified.Menu itself.

Fired on the root menu of a menu hierarchy whenever a user selects an item within the menu or within one of its direct or indirect submenus. Note: There is also a select event available for each single menu item. This event and the event of the menu items are redundant.

close

Closes the menu.

destroyItems

Destroys all the items in the aggregation items.

detachItemSelect

Detaches event handler fnFunction from the itemSelect event of this sap.ui.unified.Menu.

The passed function and listener object must match the ones used for event registration.

sap.ui.unified.Menu.extend

Creates a new subclass of class sap.ui.unified.Menu with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.Control.extend.

fireItemSelect

Fires event itemSelect to attached listeners.

getAriaDescription

Gets current value of property ariaDescription.

Accessible label / description of the menu for assistive technologies like screenreaders.

Since 1.27.0 replaced by <code>ariaLabelledBy</code> association
getAriaLabelledBy

Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.

getEnabled

Gets current value of property enabled.

When a menu is disabled none of its items can be selected by the user. The enabled property of an item (@link sap.ui.unified.MenuItemBase#getEnabled) has no effect when the menu of the item is disabled.

Default value is true.

getItems

Gets content of aggregation items.

The available actions to be displayed as items of the menu.

getMaxVisibleItems

Gets current value of property maxVisibleItems.

The maximum number of items which are displayed before an overflow mechanism takes effect. A value smaller than 1 means an infinite number of visible items. The overall height of the menu is limited by the height of the screen. If the maximum possible height is reached, an overflow takes effect, even if the maximum number of visible items is not yet reached.

Default value is 0.

sap.ui.unified.Menu.getMetadata

Returns a metadata object for class sap.ui.unified.Menu.

getPageSize

Gets current value of property pageSize.

The keyboard can be used to navigate through the items of a menu. Beside the arrow keys for single steps and the Home / End keys for jumping to the first / last item, the Page Up / Page Down keys can be used to jump an arbitrary number of items up or down. This number can be defined via the pageSize property. For values smaller than 1, paging behaves in a similar way to when using the Home / End keys. If the value equals 1, the paging behavior is similar to that of the arrow keys.

Default value is 5.

indexOfItem

Checks for the provided sap.ui.unified.MenuItemBase in the aggregation items. and returns its index if found or -1 otherwise.

insertItem

Inserts a item into the aggregation items.

open

Opens the menu at the specified position.

The position of the menu is defined relative to an element in the visible DOM by specifying the docking location of the menu and of the related element.

See Popup#open for further details about popup positioning.

openAsContextMenu

Opens the menu as a context menu.

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAllItems

Removes all the controls from the aggregation items.

Additionally, it unregisters them from the hosting UIArea.

removeAriaLabelledBy

Removes an ariaLabelledBy from the association named ariaLabelledBy.

removeItem

Removes a item from the aggregation items.

setAriaDescription

Sets a new value for property ariaDescription.

Accessible label / description of the menu for assistive technologies like screenreaders.

When called with a value of null or undefined, the default value of the property will be restored.

Since 1.27.0 replaced by <code>ariaLabelledBy</code> association
setEnabled

Sets a new value for property enabled.

When a menu is disabled none of its items can be selected by the user. The enabled property of an item (@link sap.ui.unified.MenuItemBase#getEnabled) has no effect when the menu of the item is disabled.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is true.

setMaxVisibleItems

Sets a new value for property maxVisibleItems.

The maximum number of items which are displayed before an overflow mechanism takes effect. A value smaller than 1 means an infinite number of visible items. The overall height of the menu is limited by the height of the screen. If the maximum possible height is reached, an overflow takes effect, even if the maximum number of visible items is not yet reached.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is 0.

setPageSize

Sets a new value for property pageSize.

The keyboard can be used to navigate through the items of a menu. Beside the arrow keys for single steps and the Home / End keys for jumping to the first / last item, the Page Up / Page Down keys can be used to jump an arbitrary number of items up or down. This number can be defined via the pageSize property. For values smaller than 1, paging behaves in a similar way to when using the Home / End keys. If the value equals 1, the paging behavior is similar to that of the arrow keys.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is 5.

addAriaLabelledBy

Adds some ariaLabelledBy into the association ariaLabelledBy.

Param Type DefaultValue Description
vAriaLabelledBy sap.ui.core.ID sap.ui.core.Control

The ariaLabelledBy to add; if empty, nothing is inserted

addItem

Adds some item to the aggregation items.

Param Type DefaultValue Description
oItem sap.ui.unified.MenuItemBase

The item to add; if empty, nothing is inserted

attachItemSelect

Attaches event handler fnFunction to the itemSelect event of this sap.ui.unified.Menu.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.unified.Menu itself.

Fired on the root menu of a menu hierarchy whenever a user selects an item within the menu or within one of its direct or indirect submenus. Note: There is also a select event available for each single menu item. This event and the event of the menu items are redundant.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function(sap.ui.base.Event) : void

The function to be called when the event occurs

oListener object

Context object to call the event handler with. Defaults to this sap.ui.unified.Menu itself

close

Closes the menu.

destroyItems

Destroys all the items in the aggregation items.

detachItemSelect

Detaches event handler fnFunction from the itemSelect event of this sap.ui.unified.Menu.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function(sap.ui.base.Event) : void

The function to be called, when the event occurs

oListener object

Context object on which the given function had to be called

sap.ui.unified.Menu.extend

Creates a new subclass of class sap.ui.unified.Menu with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.Control.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

fireItemSelect

Fires event itemSelect to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

item sap.ui.unified.MenuItemBase

The action (item) which was selected by the user.

getAriaDescription

Gets current value of property ariaDescription.

Accessible label / description of the menu for assistive technologies like screenreaders.

Since 1.27.0 replaced by <code>ariaLabelledBy</code> association

getAriaLabelledBy

Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.

getEnabled

Gets current value of property enabled.

When a menu is disabled none of its items can be selected by the user. The enabled property of an item (@link sap.ui.unified.MenuItemBase#getEnabled) has no effect when the menu of the item is disabled.

Default value is true.

getItems

Gets content of aggregation items.

The available actions to be displayed as items of the menu.

getMaxVisibleItems

Gets current value of property maxVisibleItems.

The maximum number of items which are displayed before an overflow mechanism takes effect. A value smaller than 1 means an infinite number of visible items. The overall height of the menu is limited by the height of the screen. If the maximum possible height is reached, an overflow takes effect, even if the maximum number of visible items is not yet reached.

Default value is 0.

sap.ui.unified.Menu.getMetadata

Returns a metadata object for class sap.ui.unified.Menu.

getPageSize

Gets current value of property pageSize.

The keyboard can be used to navigate through the items of a menu. Beside the arrow keys for single steps and the Home / End keys for jumping to the first / last item, the Page Up / Page Down keys can be used to jump an arbitrary number of items up or down. This number can be defined via the pageSize property. For values smaller than 1, paging behaves in a similar way to when using the Home / End keys. If the value equals 1, the paging behavior is similar to that of the arrow keys.

Default value is 5.

indexOfItem

Checks for the provided sap.ui.unified.MenuItemBase in the aggregation items. and returns its index if found or -1 otherwise.

Param Type DefaultValue Description
oItem sap.ui.unified.MenuItemBase

The item whose index is looked for

insertItem

Inserts a item into the aggregation items.

Param Type DefaultValue Description
oItem sap.ui.unified.MenuItemBase

The item to insert; if empty, nothing is inserted

iIndex int

The 0-based index the item should be inserted at; for a negative value of iIndex, the item is inserted at position 0; for a value greater than the current size of the aggregation, the item is inserted at the last position

open

Opens the menu at the specified position.

The position of the menu is defined relative to an element in the visible DOM by specifying the docking location of the menu and of the related element.

See Popup#open for further details about popup positioning.

Param Type DefaultValue Description
bWithKeyboard boolean

Indicates whether or not the first item shall be highlighted when the menu is opened (keyboard case)

oOpenerRef sap.ui.core.Element Element

The element which will get the focus back again after the menu was closed

my sap.ui.core.Dock

The reference docking location of the menu for positioning the menu on the screen

at sap.ui.core.Dock

The 'of' element's reference docking location for positioning the menu on the screen

of sap.ui.core.Element Element

The menu is positioned relatively to this element based on the given dock locations

offset string

The offset relative to the docking point, specified as a string with space-separated pixel values (e.g. "10 0" to move the popup 10 pixels to the right)

collision sap.ui.core.Collision

The collision defines how the position of the menu should be adjusted in case it overflows the window in some direction

openAsContextMenu

Opens the menu as a context menu.

Param Type DefaultValue Description
oEvent jQuery.Event object

The event object or an object containing offsetX, offsetY values and left, top values of the element's position

oOpenerRef sap.ui.core.Element HTMLElement

Might be UI5 Element or DOM Element

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAllItems

Removes all the controls from the aggregation items.

Additionally, it unregisters them from the hosting UIArea.

removeAriaLabelledBy

Removes an ariaLabelledBy from the association named ariaLabelledBy.

Param Type DefaultValue Description
vAriaLabelledBy int sap.ui.core.ID sap.ui.core.Control

The ariaLabelledBy to be removed or its index or ID

removeItem

Removes a item from the aggregation items.

Param Type DefaultValue Description
vItem int string sap.ui.unified.MenuItemBase

The item to remove or its index or id

setAriaDescription

Sets a new value for property ariaDescription.

Accessible label / description of the menu for assistive technologies like screenreaders.

When called with a value of null or undefined, the default value of the property will be restored.

Since 1.27.0 replaced by <code>ariaLabelledBy</code> association
Param Type DefaultValue Description
sAriaDescription string

New value for property ariaDescription

setEnabled

Sets a new value for property enabled.

When a menu is disabled none of its items can be selected by the user. The enabled property of an item (@link sap.ui.unified.MenuItemBase#getEnabled) has no effect when the menu of the item is disabled.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is true.

Param Type DefaultValue Description
bEnabled boolean true

New value for property enabled

setMaxVisibleItems

Sets a new value for property maxVisibleItems.

The maximum number of items which are displayed before an overflow mechanism takes effect. A value smaller than 1 means an infinite number of visible items. The overall height of the menu is limited by the height of the screen. If the maximum possible height is reached, an overflow takes effect, even if the maximum number of visible items is not yet reached.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is 0.

Param Type DefaultValue Description
iMaxVisibleItems int 0

New value for property maxVisibleItems

setPageSize

Sets a new value for property pageSize.

The keyboard can be used to navigate through the items of a menu. Beside the arrow keys for single steps and the Home / End keys for jumping to the first / last item, the Page Up / Page Down keys can be used to jump an arbitrary number of items up or down. This number can be defined via the pageSize property. For values smaller than 1, paging behaves in a similar way to when using the Home / End keys. If the value equals 1, the paging behavior is similar to that of the arrow keys.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is 5.

Param Type DefaultValue Description
iPageSize int 5

New value for property pageSize