Class: PopupMenu

PopupMenu()

Implements the functionality of a popup up menu to be displayed in your application. The popup menu contains of the list of the provided menu items.

PopupMenu closes itself on click event fired by window. To display the menu on click, you must mark the 'click' event as defaultPrevented using preventDefault(), so the PopupMenu will ignore it. See the example.

PopupMenu closes itself on resize and orientationchange events fired by window.

Constructor

new PopupMenu()

Implements:
Source:
Listens to Events:
  • window#event:click
  • window#event:resize
  • window#event:orientationchange
Example
// Display PopupMenu under the button
 const myButton = document.getElementById('myButton');
 const itemList = [
   new PopupMenuItem(1, 'Menu item 1'),
   new PopupMenuItem(2, 'Menu item 2'),
   new PopupMenuItem(3, 'Menu item 3')
 ];
 const position = PopupMenuPosition.alignBottomLeft(myButton);
 const selectedId = await PopupMenu.show(itemList, position);

Methods

(static) close()

Closes any existing instance of PopupMenu on the screen
Source:

(async, static) show(menuItems, position)

Displays the popup menu and returns the id of the selected item asynchronously. Example of usage: const selectedId = await PopupMenu.show(itemsList, position);
Parameters:
Name Type Description
menuItems Array.<PopupMenuItem> The list of items to be displayed
position PopupMenuPosition The position of PopupMenu
Source: