class sap.m.Menu

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

The sap.m.Menu control represents a hierarchical menu. When opened on mobile devices it occupies the whole screen.

Note: The application developer should add dependency to sap.ui.unified library on application level to ensure that the library is loaded before the module dependencies will be required. If the sap.ui.unified library is not loaded in advance, this could lead to CSP compliance issues and adds an additional waiting time. To prevent this, ensure that the sap.ui.unified library is loaded in advance.


Constructor

Constructor for a new Menu.

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.m.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
title string

Defines the Menu title.

Visibility: public

Aggregations

Default Aggregation: items

Name Cardinality Type Description
_dialog 0..1 sap.m.Dialog

Internal aggregation that contains the inner sap.m.Dialog for mobile.

_menu 0..1 sap.ui.unified.Menu

Internal aggregation that contains the inner sap.ui.unified.Menu for desktop and tablet.

items (default) 0..n sap.m.MenuItem

Defines the items contained within this control.


Events Overview

Event Description
closed

Fired when the menu is closed.

itemSelected

Fired when a MenuItem is selected.

closed

Fired when the menu is closed.

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

itemSelected

Fired when a MenuItem is selected.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object
item sap.m.MenuItem

The MenuItem which was selected.


Methods Overview

Method Description
addItem

Adds some item to the aggregation items.

attachClosed

Attaches event handler fnFunction to the closed event of this sap.m.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.m.Menu itself.

Fired when the menu is closed.

attachItemSelected

Attaches event handler fnFunction to the itemSelected event of this sap.m.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.m.Menu itself.

Fired when a MenuItem is selected.

bindItems

Binds aggregation items to model data.

See ManagedObject.bindAggregation for a detailed description of the possible properties of oBindingInfo.

close

Closes the Menu.

destroyItems

Destroys all the items in the aggregation items.

detachClosed

Detaches event handler fnFunction from the closed event of this sap.m.Menu.

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

detachItemSelected

Detaches event handler fnFunction from the itemSelected event of this sap.m.Menu.

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

sap.m.Menu.extend

Creates a new subclass of class sap.m.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.

fireClosed

Fires event closed to attached listeners.

fireItemSelected

Fires event itemSelected to attached listeners.

getItems

Gets content of aggregation items.

Defines the items contained within this control.

sap.m.Menu.getMetadata

Returns a metadata object for class sap.m.Menu.

getTitle

Gets current value of property title.

Defines the Menu title.

indexOfItem

Checks for the provided sap.m.MenuItem in the aggregation items. and returns its index if found or -1 otherwise.

init

Initializes the control.

insertItem

Inserts a item into the aggregation items.

openAsContextMenu

Opens the menu as a context menu.

openBy

Opens the Menu next to the given control.

removeAllItems

Removes all the controls from the aggregation items.

Additionally, it unregisters them from the hosting UIArea.

removeItem

Removes a item from the aggregation items.

setTitle

Sets the title of the Menu.

unbindItems

Unbinds aggregation items from model data.

addItem

Adds some item to the aggregation items.

Param Type DefaultValue Description
oItem sap.m.MenuItem

The item to add; if empty, nothing is inserted

attachClosed

Attaches event handler fnFunction to the closed event of this sap.m.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.m.Menu itself.

Fired when the menu is closed.

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.m.Menu itself

attachItemSelected

Attaches event handler fnFunction to the itemSelected event of this sap.m.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.m.Menu itself.

Fired when a MenuItem is selected.

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.m.Menu itself

bindItems

Binds aggregation items to model data.

See ManagedObject.bindAggregation for a detailed description of the possible properties of oBindingInfo.

Param Type DefaultValue Description
oBindingInfo sap.ui.base.ManagedObject.AggregationBindingInfo

The binding information

close

Closes the Menu.

destroyItems

Destroys all the items in the aggregation items.

detachClosed

Detaches event handler fnFunction from the closed event of this sap.m.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

detachItemSelected

Detaches event handler fnFunction from the itemSelected event of this sap.m.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.m.Menu.extend

Creates a new subclass of class sap.m.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

fireClosed

Fires event closed to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

fireItemSelected

Fires event itemSelected to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

item sap.m.MenuItem

The MenuItem which was selected.

getItems

Gets content of aggregation items.

Defines the items contained within this control.

sap.m.Menu.getMetadata

Returns a metadata object for class sap.m.Menu.

getTitle

Gets current value of property title.

Defines the Menu title.

indexOfItem

Checks for the provided sap.m.MenuItem in the aggregation items. and returns its index if found or -1 otherwise.

Param Type DefaultValue Description
oItem sap.m.MenuItem

The item whose index is looked for

init

Initializes the control.

insertItem

Inserts a item into the aggregation items.

Param Type DefaultValue Description
oItem sap.m.MenuItem

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

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

The reference of the opener

openBy

Opens the Menu next to the given control.

Param Type DefaultValue Description
oControl object

The control that defines the position for the menu

bWithKeyboard boolean

Whether the menu is opened with a shortcut or not

sDockMy sap.ui.core.Dock sap.ui.core.Popup.Dock.BeginTop

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

sDockAt sap.ui.core.Dock sap.ui.core.Popup.Dock.BeginBottom

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

sOffset string "0 -2"

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). If the docking of both "my" and "at" is RTL-sensitive ("begin" or "end"), this offset is automatically mirrored in the RTL case as well.

removeAllItems

Removes all the controls from the aggregation items.

Additionally, it unregisters them from the hosting UIArea.

removeItem

Removes a item from the aggregation items.

Param Type DefaultValue Description
vItem int string sap.m.MenuItem

The item to remove or its index or id

setTitle

Sets the title of the Menu.

Param Type DefaultValue Description
sTitle string

The new title of the Menu

unbindItems

Unbinds aggregation items from model data.