class sap.m.MenuButton

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

The sap.m.MenuButton control enables the user to show a hierarchical menu.

This control can be a drag source.

Constructor

Constructor for a new MenuButton.

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.MenuButton(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
activeIcon sap.ui.core.URI

The source property of an alternative icon for the active (pressed) state of the button. Both active and default icon properties should be defined and of the same type - image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

Visibility: public
buttonMode sap.m.MenuButtonMode Regular

Defines whether the MenuButton is set to Regular or Split mode.

Visibility: public
enabled boolean true

Boolean property to enable the control (default is true).
Note: Depending on custom settings, the buttons that are disabled have other colors than the enabled ones.

Visibility: public
icon sap.ui.core.URI

Defines the icon to be displayed as a graphical element within the button. It can be an image or an icon from the icon font.

Visibility: public
iconDensityAware boolean true

When set to true (default), one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server. If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

Visibility: public
menuPosition sap.ui.core.Popup.Dock BeginBottom

Specifies the position of the popup menu with enumerated options. By default, the control opens the menu at its bottom left side.

Note: In the case that the menu has no space to show itself in the view port of the current window it tries to open itself to the inverted direction.

Since: 1.56.0.

Visibility: public
text string

Defines the text of the MenuButton.
Note: In Split buttonMode with useDefaultActionOnly set to false, the text is changed to display the last selected item's text, while in Regular buttonMode the text stays unchanged.

Visibility: public
textDirection sap.ui.core.TextDirection Inherit

Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

Visibility: public
type sap.m.ButtonType Default

Defines the type of the MenuButton (for example, Default, Accept, Reject, Back, etc.)

Note: Not all existing types are valid for the control. See sap.m.ButtonType documentation.

Visibility: public
useDefaultActionOnly boolean false

Controls whether the default action handler is invoked always or it is invoked only until a menu item is selected. Usable only if buttonMode is set to Split.

Visibility: public
width sap.ui.core.CSSSize

Defines the width of the MenuButton.
Note:As per visual design this width can be maximum of 12rem (192px).

Visibility: public

Aggregations

Default Aggregation: menu

Name Cardinality Type Description
_button 0..1 sap.ui.core.Control

Internal aggregation that contains the button part.

menu (default) 0..1 sap.m.Menu

Defines the menu that opens for this button.


Associations

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

Association to controls / ids which describe this control (see WAI-ARIA attribute aria-describedby).

ariaLabelledBy 0..n sap.ui.core.Control

Association to controls / ids which label this control (see WAI-ARIA attribute aria-labelledby).


Events Overview

Event Description
beforeMenuOpen

Fired before menu opening when the buttonMode is set to Split and the user presses the arrow button.

Since: 1.94.0.

defaultAction

Fired when the buttonMode is set to Split and the user presses the main button unless useDefaultActionOnly is set to false and another action from the menu has been selected previously.

beforeMenuOpen

Fired before menu opening when the buttonMode is set to Split and the user presses the arrow button.

Since: 1.94.0.

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

defaultAction

Fired when the buttonMode is set to Split and the user presses the main button unless useDefaultActionOnly is set to false and another action from the menu has been selected previously.

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

Methods Overview

Method Description
addAriaDescribedBy

Adds some ariaDescribedBy into the association ariaDescribedBy.

addAriaLabelledBy

Adds some ariaLabelledBy into the association ariaLabelledBy.

attachBeforeMenuOpen

Attaches event handler fnFunction to the beforeMenuOpen event of this sap.m.MenuButton.

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.MenuButton itself.

Fired before menu opening when the buttonMode is set to Split and the user presses the arrow button.

attachDefaultAction

Attaches event handler fnFunction to the defaultAction event of this sap.m.MenuButton.

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.MenuButton itself.

Fired when the buttonMode is set to Split and the user presses the main button unless useDefaultActionOnly is set to false and another action from the menu has been selected previously.

destroyMenu

Destroys the menu in the aggregation menu.

detachBeforeMenuOpen

Detaches event handler fnFunction from the beforeMenuOpen event of this sap.m.MenuButton.

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

detachDefaultAction

Detaches event handler fnFunction from the defaultAction event of this sap.m.MenuButton.

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

sap.m.MenuButton.extend

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

fireBeforeMenuOpen

Fires event beforeMenuOpen to attached listeners.

fireDefaultAction

Fires event defaultAction to attached listeners.

getActiveIcon

Gets current value of property activeIcon.

The source property of an alternative icon for the active (pressed) state of the button. Both active and default icon properties should be defined and of the same type - image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

getAriaDescribedBy

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

getAriaLabelledBy

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

getButtonMode

Gets current value of property buttonMode.

Defines whether the MenuButton is set to Regular or Split mode.

Default value is Regular.

getEnabled

Gets current value of property enabled.

Boolean property to enable the control (default is true).
Note: Depending on custom settings, the buttons that are disabled have other colors than the enabled ones.

Default value is true.

getIcon

Gets current value of property icon.

Defines the icon to be displayed as a graphical element within the button. It can be an image or an icon from the icon font.

getIconDensityAware

Gets current value of property iconDensityAware.

When set to true (default), one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server. If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

Default value is true.

getIdForLabel

Returns the DOMNode Id to be used for the "labelFor" attribute of the label.

By default, this is the Id of the control itself.

getMenu

Gets content of aggregation menu.

Defines the menu that opens for this button.

getMenuPosition

Gets current value of property menuPosition.

Specifies the position of the popup menu with enumerated options. By default, the control opens the menu at its bottom left side.

Note: In the case that the menu has no space to show itself in the view port of the current window it tries to open itself to the inverted direction.

Default value is BeginBottom.

sap.m.MenuButton.getMetadata

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

getText

Gets current value of property text.

Defines the text of the MenuButton.
Note: In Split buttonMode with useDefaultActionOnly set to false, the text is changed to display the last selected item's text, while in Regular buttonMode the text stays unchanged.

getTextDirection

Gets current value of property textDirection.

Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

Default value is Inherit.

getType

Gets current value of property type.

Defines the type of the MenuButton (for example, Default, Accept, Reject, Back, etc.)

Note: Not all existing types are valid for the control. See sap.m.ButtonType documentation.

Default value is Default.

getUseDefaultActionOnly

Gets current value of property useDefaultActionOnly.

Controls whether the default action handler is invoked always or it is invoked only until a menu item is selected. Usable only if buttonMode is set to Split.

Default value is false.

getWidth

Gets current value of property width.

Defines the width of the MenuButton.
Note:As per visual design this width can be maximum of 12rem (192px).

init

Initializes the control.

removeAllAriaDescribedBy

Removes all the controls in the association named ariaDescribedBy.

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAriaDescribedBy

Removes an ariaDescribedBy from the association named ariaDescribedBy.

removeAriaLabelledBy

Removes an ariaLabelledBy from the association named ariaLabelledBy.

setActiveIcon

Sets a new value for property activeIcon.

The source property of an alternative icon for the active (pressed) state of the button. Both active and default icon properties should be defined and of the same type - image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

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

setButtonMode

Sets the buttonMode of the control.

setEnabled

Sets a new value for property enabled.

Boolean property to enable the control (default is true).
Note: Depending on custom settings, the buttons that are disabled have other colors than the enabled ones.

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

Default value is true.

setIcon

Sets a new value for property icon.

Defines the icon to be displayed as a graphical element within the button. It can be an image or an icon from the icon font.

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

setIconDensityAware

Sets a new value for property iconDensityAware.

When set to true (default), one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server. If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

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

Default value is true.

setMenu

Sets the aggregated menu.

setMenuPosition

Sets a new value for property menuPosition.

Specifies the position of the popup menu with enumerated options. By default, the control opens the menu at its bottom left side.

Note: In the case that the menu has no space to show itself in the view port of the current window it tries to open itself to the inverted direction.

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

Default value is BeginBottom.

setText

Sets a new value for property text.

Defines the text of the MenuButton.
Note: In Split buttonMode with useDefaultActionOnly set to false, the text is changed to display the last selected item's text, while in Regular buttonMode the text stays unchanged.

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

setTextDirection

Sets a new value for property textDirection.

Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

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

Default value is Inherit.

setTooltip

Sets the tooltip for the MenuButton. Can either be an instance of a TooltipBase subclass or a simple string.

setType

Sets a new value for property type.

Defines the type of the MenuButton (for example, Default, Accept, Reject, Back, etc.)

Note: Not all existing types are valid for the control. See sap.m.ButtonType documentation.

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

Default value is Default.

setUseDefaultActionOnly

Sets a new value for property useDefaultActionOnly.

Controls whether the default action handler is invoked always or it is invoked only until a menu item is selected. Usable only if buttonMode is set to Split.

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

Default value is false.

setWidth

Sets a new value for property width.

Defines the width of the MenuButton.
Note:As per visual design this width can be maximum of 12rem (192px).

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

addAriaDescribedBy

Adds some ariaDescribedBy into the association ariaDescribedBy.

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

The ariaDescribedBy to add; if empty, nothing is inserted

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

attachBeforeMenuOpen

Attaches event handler fnFunction to the beforeMenuOpen event of this sap.m.MenuButton.

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.MenuButton itself.

Fired before menu opening when the buttonMode is set to Split and the user presses the arrow button.

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.MenuButton itself

attachDefaultAction

Attaches event handler fnFunction to the defaultAction event of this sap.m.MenuButton.

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.MenuButton itself.

Fired when the buttonMode is set to Split and the user presses the main button unless useDefaultActionOnly is set to false and another action from the menu has been selected previously.

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.MenuButton itself

destroyMenu

Destroys the menu in the aggregation menu.

detachBeforeMenuOpen

Detaches event handler fnFunction from the beforeMenuOpen event of this sap.m.MenuButton.

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

detachDefaultAction

Detaches event handler fnFunction from the defaultAction event of this sap.m.MenuButton.

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.MenuButton.extend

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

fireBeforeMenuOpen

Fires event beforeMenuOpen to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

fireDefaultAction

Fires event defaultAction to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

getActiveIcon

Gets current value of property activeIcon.

The source property of an alternative icon for the active (pressed) state of the button. Both active and default icon properties should be defined and of the same type - image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

getAriaDescribedBy

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

getAriaLabelledBy

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

getButtonMode

Gets current value of property buttonMode.

Defines whether the MenuButton is set to Regular or Split mode.

Default value is Regular.

getEnabled

Gets current value of property enabled.

Boolean property to enable the control (default is true).
Note: Depending on custom settings, the buttons that are disabled have other colors than the enabled ones.

Default value is true.

getIcon

Gets current value of property icon.

Defines the icon to be displayed as a graphical element within the button. It can be an image or an icon from the icon font.

getIconDensityAware

Gets current value of property iconDensityAware.

When set to true (default), one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server. If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

Default value is true.

getIdForLabel

Returns the DOMNode Id to be used for the "labelFor" attribute of the label.

By default, this is the Id of the control itself.

getMenu

Gets content of aggregation menu.

Defines the menu that opens for this button.

getMenuPosition

Gets current value of property menuPosition.

Specifies the position of the popup menu with enumerated options. By default, the control opens the menu at its bottom left side.

Note: In the case that the menu has no space to show itself in the view port of the current window it tries to open itself to the inverted direction.

Default value is BeginBottom.

sap.m.MenuButton.getMetadata

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

getText

Gets current value of property text.

Defines the text of the MenuButton.
Note: In Split buttonMode with useDefaultActionOnly set to false, the text is changed to display the last selected item's text, while in Regular buttonMode the text stays unchanged.

getTextDirection

Gets current value of property textDirection.

Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

Default value is Inherit.

getType

Gets current value of property type.

Defines the type of the MenuButton (for example, Default, Accept, Reject, Back, etc.)

Note: Not all existing types are valid for the control. See sap.m.ButtonType documentation.

Default value is Default.

getUseDefaultActionOnly

Gets current value of property useDefaultActionOnly.

Controls whether the default action handler is invoked always or it is invoked only until a menu item is selected. Usable only if buttonMode is set to Split.

Default value is false.

getWidth

Gets current value of property width.

Defines the width of the MenuButton.
Note:As per visual design this width can be maximum of 12rem (192px).

init

Initializes the control.

removeAllAriaDescribedBy

Removes all the controls in the association named ariaDescribedBy.

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAriaDescribedBy

Removes an ariaDescribedBy from the association named ariaDescribedBy.

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

The ariaDescribedBy to be removed or its index or ID

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

setActiveIcon

Sets a new value for property activeIcon.

The source property of an alternative icon for the active (pressed) state of the button. Both active and default icon properties should be defined and of the same type - image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

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

Param Type DefaultValue Description
sActiveIcon sap.ui.core.URI

New value for property activeIcon

setButtonMode

Sets the buttonMode of the control.

Param Type DefaultValue Description
sMode sap.m.MenuButtonMode

The new button mode

setEnabled

Sets a new value for property enabled.

Boolean property to enable the control (default is true).
Note: Depending on custom settings, the buttons that are disabled have other colors than the enabled ones.

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

setIcon

Sets a new value for property icon.

Defines the icon to be displayed as a graphical element within the button. It can be an image or an icon from the icon font.

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

Param Type DefaultValue Description
sIcon sap.ui.core.URI

New value for property icon

setIconDensityAware

Sets a new value for property iconDensityAware.

When set to true (default), one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server. If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

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
bIconDensityAware boolean true

New value for property iconDensityAware

setMenu

Sets the aggregated menu.

Param Type DefaultValue Description
oMenu sap.m.Menu

The menu to set

setMenuPosition

Sets a new value for property menuPosition.

Specifies the position of the popup menu with enumerated options. By default, the control opens the menu at its bottom left side.

Note: In the case that the menu has no space to show itself in the view port of the current window it tries to open itself to the inverted direction.

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

Default value is BeginBottom.

Param Type DefaultValue Description
sMenuPosition sap.ui.core.Popup.Dock BeginBottom

New value for property menuPosition

setText

Sets a new value for property text.

Defines the text of the MenuButton.
Note: In Split buttonMode with useDefaultActionOnly set to false, the text is changed to display the last selected item's text, while in Regular buttonMode the text stays unchanged.

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

Param Type DefaultValue Description
sText string

New value for property text

setTextDirection

Sets a new value for property textDirection.

Specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

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

Default value is Inherit.

Param Type DefaultValue Description
sTextDirection sap.ui.core.TextDirection Inherit

New value for property textDirection

setTooltip

Sets the tooltip for the MenuButton. Can either be an instance of a TooltipBase subclass or a simple string.

Param Type DefaultValue Description
vTooltip sap.ui.core.TooltipBase

The tooltip that should be shown.

setType

Sets a new value for property type.

Defines the type of the MenuButton (for example, Default, Accept, Reject, Back, etc.)

Note: Not all existing types are valid for the control. See sap.m.ButtonType documentation.

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

Default value is Default.

Param Type DefaultValue Description
sType sap.m.ButtonType Default

New value for property type

setUseDefaultActionOnly

Sets a new value for property useDefaultActionOnly.

Controls whether the default action handler is invoked always or it is invoked only until a menu item is selected. Usable only if buttonMode is set to Split.

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

Default value is false.

Param Type DefaultValue Description
bUseDefaultActionOnly boolean false

New value for property useDefaultActionOnly

setWidth

Sets a new value for property width.

Defines the width of the MenuButton.
Note:As per visual design this width can be maximum of 12rem (192px).

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

Param Type DefaultValue Description
sWidth sap.ui.core.CSSSize

New value for property width