Class sap.ui.unified.MenuModule: sap/ui/unified/Menu

extends Control
known direct subclasses: ColumnMenu, Menu

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.


Since: 1.21.0.
Constructor Summary
new sap.ui.unified.Menu(sId?, mSettings?)Constructor for a new Menu control.
Event Summary
itemSelect(oControlEvent)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.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.ui.unified.Menu.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.unified.Menu with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.unified.Menu.getMetadata()Returns a metadata object for class sap.ui.unified.Menu.
addAriaLabelledBy(vAriaLabelledBy)Adds some ariaLabelledBy into the association ariaLabelledBy.
addItem(oItem)Adds some item to the aggregation items.
attachItemSelect(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the itemSelect event of this sap.ui.unified.Menu.
close()Closes the menu.
destroyItems()Destroys all the items in the aggregation items.
detachItemSelect(fnFunction, oListener)Detaches event handler fnFunction from the itemSelect event of this sap.ui.unified.Menu.
fireItemSelect(mArguments?)Fires event itemSelect to attached listeners.
getAriaLabelledBy()Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
getEnabled()Gets current value of property enabled.
getItems()Gets content of aggregation items.
getMaxVisibleItems()Gets current value of property maxVisibleItems.
getPageSize()Gets current value of property pageSize.
indexOfItem(oItem)Checks for the provided sap.ui.unified.MenuItemBase in the aggregation items.
insertItem(oItem, iIndex)Inserts a item into the aggregation items.
open(bWithKeyboard, oOpenerRef, sMy, sAt, oOf, sOffset?, sCollision?)Opens the menu at the specified position.
removeAllAriaLabelledBy()Removes all the controls in the association named ariaLabelledBy.
removeAllItems()Removes all the controls from the aggregation items.
removeAriaLabelledBy(vAriaLabelledBy)Removes an ariaLabelledBy from the association named ariaLabelledBy.
removeItem(vItem)Removes a item from the aggregation items.
setEnabled(bEnabled)Sets a new value for property enabled.
setMaxVisibleItems(iMaxVisibleItems)Sets a new value for property maxVisibleItems.
setPageSize(iPageSize)Sets a new value for property pageSize.
getAriaDescription()Gets current value of property ariaDescription.
setAriaDescription(sAriaDescription)Sets a new value for property ariaDescription.
Constructor Detail
new sap.ui.unified.Menu(sId?, mSettings?)
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 for a general description of the syntax of the settings object.

The supported settings are:

  • Properties
  • Aggregations
    • items : sap.ui.unified.MenuItemBase[] (default)
  • Events
    • itemSelect : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]

In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.

Parameters:
{string}sId? Id for the new control, generated automatically if no id is given
{object}mSettings? Initial settings for the new control
Event Detail
itemSelect(oControlEvent)
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.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
{sap.ui.unified.MenuItemBase}oControlEvent.getParameters.item The action (item) which was selected by the user.
Method Detail
sap.ui.unified.Menu.extend(sClassName, oClassInfo?, FNMetaImpl?): function
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.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.ui.unified.Menu.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.unified.Menu.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
addAriaLabelledBy(vAriaLabelledBy): sap.ui.unified.Menu
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
{string|sap.ui.core.Control}vAriaLabelledBy the ariaLabelledBy to add; if empty, nothing is inserted
Since:
1.26.3
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
addItem(oItem): sap.ui.unified.Menu
Adds some item to the aggregation items.
Parameters:
{sap.ui.unified.MenuItemBase}oItem the item to add; if empty, nothing is inserted
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
attachItemSelect(oData?, fnFunction, oListener?): sap.ui.unified.Menu
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.

Parameters:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.ui.unified.Menu itself
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
close(): void
Closes the menu.
destroyItems(): sap.ui.unified.Menu
Destroys all the items in the aggregation items.
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
detachItemSelect(fnFunction, oListener): sap.ui.unified.Menu
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.

Parameters:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
fireItemSelect(mArguments?): sap.ui.unified.Menu
Fires event itemSelect to attached listeners.

Expects the following event parameters:

  • item of type sap.ui.unified.MenuItemBaseThe action (item) which was selected by the user.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
getAriaLabelledBy(): sap.ui.core.Control[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Since:
1.26.3
Returns:
{sap.ui.core.Control[]}
getEnabled(): boolean
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.

Returns:
{boolean} Value of property enabled
Gets content of aggregation items.

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

Returns:
{sap.ui.unified.MenuItemBase[]}
getMaxVisibleItems(): int
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.

Returns:
{int} Value of property maxVisibleItems
getPageSize(): int
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.

Since:
1.25.0
Returns:
{int} Value of property pageSize
indexOfItem(oItem): int
Checks for the provided sap.ui.unified.MenuItemBase in the aggregation items. and returns its index if found or -1 otherwise.
Parameters:
{sap.ui.unified.MenuItemBase}oItem The item whose index is looked for
Returns:
{int} The index of the provided control in the aggregation if found, or -1 otherwise
insertItem(oItem, iIndex): sap.ui.unified.Menu
Inserts a item into the aggregation items.
Parameters:
{sap.ui.unified.MenuItemBase}oItem the item to insert; if empty, nothing is inserted
{int}iIndex 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
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
open(bWithKeyboard, oOpenerRef, sMy, sAt, oOf, sOffset?, sCollision?): void
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.

Parameters:
{boolean}bWithKeyboard Indicates whether or not the first item shall be highlighted when the menu is opened (keyboard case)
{sap.ui.core.Element|DOMRef}oOpenerRef The element which will get the focus back again after the menu was closed
{sap.ui.core.Dock}sMy The reference docking location of the menu for positioning the menu on the screen
{sap.ui.core.Dock}sAt The 'of' element's reference docking location for positioning the menu on the screen
{sap.ui.core.Element|DOMRef}oOf The menu is positioned relatively to this element based on the given dock locations
{string}sOffset? The offset relative to the docking point, specified as a string with space-separated pixel values (e.g. "0 10" to move the popup 10 pixels to the right)
{sap.ui.core.Collision}sCollision? The collision defines how the position of the menu should be adjusted in case it overflows the window in some direction
removeAllAriaLabelledBy(): sap.ui.core.Control[]
Removes all the controls in the association named ariaLabelledBy.
Since:
1.26.3
Returns:
{sap.ui.core.Control[]} An array of the removed elements (might be empty)
removeAllItems(): sap.ui.unified.MenuItemBase[]
Removes all the controls from the aggregation items.

Additionally, it unregisters them from the hosting UIArea.

Returns:
{sap.ui.unified.MenuItemBase[]} An array of the removed elements (might be empty)
removeAriaLabelledBy(vAriaLabelledBy): sap.ui.core.Control
Removes an ariaLabelledBy from the association named ariaLabelledBy.
Parameters:
{int|string|sap.ui.core.Control}vAriaLabelledBy The ariaLabelledByto be removed or its index or ID
Since:
1.26.3
Returns:
{sap.ui.core.Control} the removed ariaLabelledBy or null
removeItem(vItem): sap.ui.unified.MenuItemBase
Removes a item from the aggregation items.
Parameters:
{int|string|sap.ui.unified.MenuItemBase}vItem The itemto remove or its index or id
Returns:
{sap.ui.unified.MenuItemBase} The removed item or null
setEnabled(bEnabled): sap.ui.unified.Menu
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.

Parameters:
{boolean}bEnabled New value for property enabled
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
setMaxVisibleItems(iMaxVisibleItems): sap.ui.unified.Menu
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.

Parameters:
{int}iMaxVisibleItems New value for property maxVisibleItems
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
setPageSize(iPageSize): sap.ui.unified.Menu
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.

Parameters:
{int}iPageSize New value for property pageSize
Since:
1.25.0
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining
getAriaDescription(): string
Gets current value of property ariaDescription.

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

Deprecated:
Since version 1.27.0 Please use association ariaLabelledBy instead.
Returns:
{string} Value of property ariaDescription
setAriaDescription(sAriaDescription): sap.ui.unified.Menu
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.

Parameters:
{string}sAriaDescription New value for property ariaDescription
Deprecated:
Since version 1.27.0 Please use association ariaLabelledBy instead.
Returns:
{sap.ui.unified.Menu} Reference to this in order to allow method chaining