abap2UI5

Item Eventing

Menu with Item Eventing

Z2UI5_CL_SMPC_APP_227

Controls sap.ui.unified UI5 1.84

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_227
Source file
z2ui5_cl_smpc_app_227.clas.abap
Library
sap.ui.unified
UI5 entity
sap.ui.unified.Menu
Demo kit sample
sap.ui.unified.sample.MenuItemEventing
SAP's own sample
running at sdk.openui5.org ↗
Minimum UI5
1.84
In the playground
runs in the browser, with no system and nothing installed

Keywords: menu, sap.ui.unified, menuitemeventing, horizontallayout, button, menuitem, menutextfielditem

Controls it builds

Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.

Libraries

Run it here

The sample running, in this page — the app on its own, with no editor over it. Switch to Playground with this code

Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.

The ABAP

z2ui5_cl_smpc_app_227.clas.abap — 116 lines Read it on GitHub ↗
" @keywords menu sap.ui.unified menuitemeventing horizontallayout button menuitem menutextfielditem
" @summary Menu with Item Eventing
CLASS z2ui5_cl_smpc_app_227 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_227 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_navigated( ).
      view_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

    DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).

    view->ele( n = `View` ns = `mvc`
        )->a( n = `xmlns`     v = `sap.m`
        )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
        )->a( n = `xmlns:l`   v = `sap.ui.layout`
        )->a( n = `xmlns:u`   v = `sap.ui.unified`
        )->a( n = `class`     v = `viewPadding`

        )->ele( n = `HorizontalLayout` ns = `l`

            )->ele( `Button`
                )->a( n = `id`           v = `openMenu`
                )->a( n = `text`         v = `Open Menu`
                )->a( n = `ariaHasPopup` v = `Menu`
                " the sample opens the Menu anchored to the button via oMenu.open( kbd, button, ... );
                " sap.ui.unified.Menu has no openBy of its own; the frontend's openBy
                " falls back to open( false, anchor, 'begin top', 'begin bottom', anchor )
                " for exactly this control (pr/unified-menu-open-anchored, 2026-07-27) -
                " the "no-op today" this comment claimed until 2026-08-23 is long gone
                )->a( n = `press`        v = client->follow_up_action( val   = client->cs_event-control_by_id
                                                                       t_arg = VALUE #( ( `theMenu` ) ( `openBy` ) ( `$event.oSource.sId` ) ) )

                )->ele( `dependents`
                    )->ele( n = `Menu` ns = `u`
                        )->a( n = `id` v = `theMenu`

                        )->tag( n = `MenuItem` ns = `u`
                            )->a( n = `text`   v = `My 1st Item`
                            )->a( n = `icon`   v = `sap-icon://save`
                            " compose the toast on the frontend (1:1 with MessageToast.show("'" + item.getText() + "' pressed"))
                            )->a( n = `select` v = client->follow_up_action( val   = client->cs_event-control_global
                                                                             t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )
                        )->tag( n = `MenuItem` ns = `u`
                            )->a( n = `text`   v = `My 2nd Item`
                            )->a( n = `select` v = client->follow_up_action( val   = client->cs_event-control_global
                                                                             t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )

                        )->ele( n = `MenuItem` ns = `u`
                            )->a( n = `text` v = `My 3rd Item`

                            )->ele( n = `Menu` ns = `u`

                                )->tag( n = `MenuItem` ns = `u`
                                    )->a( n = `text`   v = `1st Sub Item`
                                    )->a( n = `select` v = client->follow_up_action( val   = client->cs_event-control_global
                                                                                     t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )
                                )->tag( n = `MenuItem` ns = `u`
                                    )->a( n = `text`   v = `2nd Sub Item`
                                    )->a( n = `select` v = client->follow_up_action( val   = client->cs_event-control_global
                                                                                     t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )
                                )->tag( n = `MenuItem` ns = `u`
                                    )->a( n = `text`    v = `3rd Sub Item but inactive`
                                    )->a( n = `enabled` v = `false`

                            )->end(
                        )->end(
                        )->tag( n = `MenuItem` ns = `u`
                            )->a( n = `text`          v = `My 4th Item`
                            )->a( n = `startsSection` v = `true`
                            )->a( n = `select`        v = client->follow_up_action( val   = client->cs_event-control_global
                                                                                    t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )
                        )->tag( n = `MenuItem` ns = `u`
                            )->a( n = `text`   v = `My 5th Item`
                            )->a( n = `select` v = client->follow_up_action( val   = client->cs_event-control_global
                                                                             t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' pressed` ) ( `${$parameters>/item}.getText()` ) ) )

                        )->tag( n = `MenuTextFieldItem` ns = `u`
                            )->a( n = `label`         v = `Find`
                            )->a( n = `enabled`       v = `true`
                            )->a( n = `startsSection` v = `true`
                            )->a( n = `icon`          v = `sap-icon://filter`
                            " 1:1 with MessageToast.show("'" + item.getValue() + "' entered")
                            )->a( n = `select`        v = client->follow_up_action( val   = client->cs_event-control_global
                                                                                    t_arg = VALUE #( ( `MESSAGE_TOAST` ) ( `show` ) ( `'{0}' entered` ) ( `${$parameters>/item}.getValue()` ) ) )

                    )->end(
                )->end(
            )->end(
        )->end( ).

    client->view_display( view->stringify( ) ).

  ENDMETHOD.

ENDCLASS.

More in sap.ui.unified

Search every abap2UI5 sample · the full list on one page

On this page