v7.3.0

Menu
Widget

A popup menu that displays a list of items which the user can activate using mouse or keyboard. Menu items can be plain actions, checkable toggles, or nested submenus (via menu). Menus are typically shown on right-click or attached to a Button via its menu config. The item event fires when any item is activated, and toggle fires when a checkable item changes state.

A common usecase is to attach a menu to a Button, which is supported via the menu config.

Useful configs and events

Config / Event Description
items Menu items (MenuItems, separators, widgets)
focusOnHover Focus menu items on mouse hover
item Fired when a menu item is activated
toggle Fired when a checkable menu item's state changes
anchor Show an anchor arrow pointing to the invoking element

See also

  • MenuItem - Individual menu item widget
  • Button - Button with built-in menu support
  • Popup - Base floating popup class

Menu item interaction handling in a complex widget

In the case of a menu which is part of a complex UI within a larger Bryntum widget, use of the string form for handlers is advised. A handler which starts with 'up.' will be resolved by looking in owning widgets of the Menu. For example a Calendar may have handlers for its MenuItems configured in:

new Calendar({
    appendTo : document.body,
    project  : myProjectConfig,
    tbar  : {
        items : {
            settings : {
                type : 'button',
                text : 'Settings',

// High weight so it goes at the end weight : 800, menu : [{ text : 'Hide non-working days', checked : false,

// The Menu's ownership will be traversed to find this function name. onToggle : 'up.toggleHideNonWorkingDays' }, { text : 'Clear changes',

// The Menu's ownership will be traversed to find this function name. onItem : 'up.clearUncommittedChanges' }] } } },

// Menu handlers found here toggleHideNonWorkingDays({ checked }) { // Use Calendar API which creates event in the selected date this.hideNonWorkingDays = checked; },

clearUncommittedChanges() { // Clear changes to our event store which are not yet synced to the server this.eventStore.revertChanges(); } });
let menu = new Menu({
    forElement : btn.element,
    items      : [
        {
            icon : 'b-icon b-icon-add',
            text : 'Add'
        },
        {
            icon : 'b-icon b-icon-trash',
            text : 'Remove'
        },
        {
            icon     : 'b-icon b-icon-lock',
            disabled : true,
            text     : 'I am disabled'
        },
        {
            text : 'Sub menu',
            menu : [{
                icon : 'fa fa-play',
                text : 'Play'
            }]
        }
    ],
    // Method is called for all ancestor levels
    onItem({ item }) {
        Toast.show('You clicked ' + item.text);
    }
});
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Specify false to prevent the menu from getting focus when hovering items

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isMenu : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of Menu class, or subclass thereof.
  • currentSubMenu : Menu
    READONLY

    Currently open sub menu, if any

  • isSubMenu : Boolean
    READONLY

    Returns true if this menu is a sub menu. To find out which menu is the parent, check parentMenu.

  • parentMenu : Menu
    READONLY

    Gets the parent Menu if this Menu is a submenu, or undefined.

  • rootMenu : Menu
    private
    READONLY

    Gets this menus root menu, the very first menu shown in a sub menu hierarchy

  • Get/set focused menu item. Shows submenu if newly focused item has a menu and is not disabled.

  • isMenu : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of Menu class, or subclass thereof.

Functions

Functions are methods available for calling on the class
    • onInternalKeyDown( )
      private

      Keyboard navigation. Up/down, close with esc, activate with enter

    • onMouseClick( )
      private

      Activates a menu item if user clicks on it

    • onMouseOver( )
      private

      Activates menu items on hover. On real mouse hover, not on a touchstart.

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    CSS variables

    CSS variables that can be set to adjust appearance
    Name Description
    --b-menu-background Menu background
    --b-menu-border-radius Menu border-radius
    --b-menu-padding Menu padding
    type: menu

    Source path

    Core/widget/Menu.js

    Contents