Skip to content

Menubar Toggle ​

A link or button that controls the visibility of a Menubar.

Note

This is a subclass of BaseMenuToggle.

Constructor ​

Constructs a new MenubarToggle.

js
new MenubarToggle({
  menuToggleElement,
  parentElement,
  controlledMenu,
  parentMenu,
  initialize,
});

The constructor will call BaseMenuToggle's constructor with the provided options. It will also initialize the menu toggle if the initialize flag is set to true.

Parameters ​

NameTypeDescriptionDefault
optionsobjectThe options for generating the menu toggle.undefined
options.menuToggleElementHTMLElementThe toggle element in the DOM.undefined
options.parentElementHTMLElementThe element containing the controlled menu.undefined
options.controlledMenuMenubarThe menu controlled by this toggle.undefined
options.parentMenuMenubar, nullThe menu containing this toggle.null
options.initializebooleanA flag to initialize the menu toggle immediately upon creation.true

Initialize ​

The initialize method is inherited from the BaseMenuToggle class. There are no customizations for the MenubarToggle class.

Properties ​

Properties are inherited from the BaseMenuToggle class. There are no custom properties for the MenubarToggle class.

Getters and Setters ​

Getters and setters are inherited from the BaseMenuToggle class. There are no custom getters and setters for the MenubarToggle class.

Methods ​

Methods are inherited from the BaseMenuToggle class. The following methods are unique to or overwritten in the MenubarToggle class.

_setAriaAttributes protected ​

Sets the ARIA attributes on the toggle and controlled menu.

js
MenubarToggle._setAriaAttributes();

Calls the BaseMenuToggle's _setAriaAttributes method.

Then sets the toggle's aria-haspopup attribute to "true".

open public ​

Opens the controlled menu.

js
MenubarToggle.open();

Calls the closeSiblings (inherited) method and then BaseMenuToggle's open method.

preview public ​

Opens the controlled menu without the current focus entering it.

js
MenubarToggle.preview();

Calls the closeSiblings (inherited) method and then BaseMenuToggle's preview method.

close public ​

Closes the controlled menu.

js
MenubarToggle.close();

Calls the closeChildren (inherited) method. If the controlled menu contained focus, restores focus to its parent item. Then calls BaseMenuToggle's close method.

When keyboard focus leaves the menubar, its submenus collapse without restoring focus to an item inside it.