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

extends Control
implements IContextMenu
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(mParameters?)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, my, at, of, offset?, collision?)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)

  • Associations

  • 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:
stringsId?Id for the new control, generated automatically if no id is given
objectmSettings?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.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
sap.ui.unified.MenuItemBaseoControlEvent.getParameters.itemThe 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:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated 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.MetadataMetadata object describing this class
addAriaLabelledBy(vAriaLabelledBy): sap.ui.unified.Menu
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledBythe ariaLabelledBy to add; if empty, nothing is inserted
Returns:
sap.ui.unified.MenuReference to this in order to allow method chaining
Since:
1.26.3
addItem(oItem): sap.ui.unified.Menu
Adds some item to the aggregation items.
Parameters:
sap.ui.unified.MenuItemBaseoItemthe item to add; if empty, nothing is inserted
Returns:
sap.ui.unified.MenuReference 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:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.unified.Menu itself
Returns:
sap.ui.unified.MenuReference 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.MenuReference 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:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.unified.MenuReference to this in order to allow method chaining
fireItemSelect(mParameters?): sap.ui.unified.Menu
Fires event itemSelect to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
sap.ui.unified.MenuItemBasemParameters.item?The action (item) which was selected by the user.
Returns:
sap.ui.unified.MenuReference to this in order to allow method chaining
getAriaLabelledBy(): sap.ui.core.ID[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Returns:
sap.ui.core.ID[]
Since:
1.26.3
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:
booleanValue 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:
intValue 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.

Returns:
intValue of property pageSize
Since:
1.25.0
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.MenuItemBaseoItemThe item whose index is looked for
Returns:
intThe 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.MenuItemBaseoItemthe item to insert; if empty, nothing is inserted
intiIndexthe 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.MenuReference to this in order to allow method chaining
open(bWithKeyboard, oOpenerRef, my, at, of, offset?, collision?): 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:
booleanbWithKeyboardIndicates whether or not the first item shall be highlighted when the menu is opened (keyboard case)
sap.ui.core.Element|DOMRefoOpenerRefThe element which will get the focus back again after the menu was closed
sap.ui.core.DockmyThe reference docking location of the menu for positioning the menu on the screen
sap.ui.core.DockatThe 'of' element's reference docking location for positioning the menu on the screen
sap.ui.core.Element|DOMRefofThe menu is positioned relatively to this element based on the given dock locations
stringoffset?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.Collisioncollision?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.ID[]
Removes all the controls in the association named ariaLabelledBy.
Returns:
sap.ui.core.ID[]An array of the removed elements (might be empty)
Since:
1.26.3
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.ID
Removes an ariaLabelledBy from the association named ariaLabelledBy.
Parameters:
int|sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledByThe ariaLabelledBy to be removed or its index or ID
Returns:
sap.ui.core.IDThe removed ariaLabelledBy or null
Since:
1.26.3
removeItem(vItem): sap.ui.unified.MenuItemBase
Removes a item from the aggregation items.
Parameters:
int|string|sap.ui.unified.MenuItemBasevItemThe item to remove or its index or id
Returns:
sap.ui.unified.MenuItemBaseThe 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:
booleanbEnabledNew value for property enabled
Returns:
sap.ui.unified.MenuReference 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:
intiMaxVisibleItemsNew value for property maxVisibleItems
Returns:
sap.ui.unified.MenuReference 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:
intiPageSizeNew value for property pageSize
Returns:
sap.ui.unified.MenuReference to this in order to allow method chaining
Since:
1.25.0
getAriaDescription(): string

Gets current value of property ariaDescription.

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

Returns:
stringValue of property ariaDescription
Deprecated API:
Since version 1.27.0 Please use association ariaLabelledBy instead.
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:
stringsAriaDescriptionNew value for property ariaDescription
Returns:
sap.ui.unified.MenuReference to this in order to allow method chaining
Deprecated API:
Since version 1.27.0 Please use association ariaLabelledBy instead.