Class: MenuComponent

MenuComponent(dataObjectopt, optionsopt)

MenuComponent holds a set of menu item Components and a ToggleComponent to show and hide the menu. This class is often used as a base class and in the extending constructor it loads its menu items but it's also possible to use it directly (see below).

Constructor

Parameters:
Name Type Attributes Default Description
dataObject DataModel <optional>
null
options Object <optional>
null
Source:
Example

Directly create a three item menu

const menuComponent = new MenuComponent()
menuComponent.appendMenuItem(new MyMenuItemComponent(...))
menuComponent.appendMenuItem(new MyMenuItemComponent(...))
menuComponent.appendMenuItem(new MyMenuItemComponent(...))

menuComponent.addListener(MenuComponent.SelectedEvent, (eventName, menuComponent, selectedIndex) => {
	const menuItemComponent = menuComponent.menuItems[selectedIndex]
})

menuComponent.addListener(ToggleComponent.ToggleEvent, (eventName, menuComponent, isOpen) => {
	// react to the change here
})

Members

Type:
Source:

opened :boolean

true if the toggle component is open
Type:
  • boolean
Source:

selectedIndex :number

Type:
  • number
Source:

selectedIndex

Source:

toggleComponent :ToggleComponent

Type:
Source:

Methods

appendMenuItem(component)

Parameters:
Name Type Description
component Component A menu item Component to add to the menu
Source:

close()

Close the toggle component
Source:

open()

Open the toggle component
Source:

toggle(open)

Toggle the toggle component open or closed
Parameters:
Name Type Description
open boolean
Source:

toggleMenuItemVisibility(index, visible)

Parameters:
Name Type Description
index number the index of the menu item to toggle
visible boolean whether to show or hide the menu item
Source: