Skip to content

Treeview Toggle

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

Note

This is a subclass of BaseMenuToggle.

Constructor

Constructs a new TreeviewToggle.

js
new TreeviewToggle({
  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.controlledMenuTreeviewThe menu controlled by this toggle.undefined
options.parentMenuTreeview, nullThe menu containing this toggle.null
options.initializebooleanA flag to initialize the menu toggle immediately upon creation.true

Initialize

Initializes the menu toggle.

js
TreeviewToggle.initialize();

The first steps are to ensure that the toggle and controlled menu have IDs using the setIds method, and to set the ARIA attributes on the toggle and controlled menu using the setAriaAttributes method.

Then the open or collapse method is called based on the state of the toggle's aria-expanded attribute.

Properties

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

Getters and Setters

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

Methods

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

_setAriaAttributes protected

Sets the ARIA attributes on the toggle and controlled menu.

js
TreeviewToggle._setAriaAttributes();

The first steps are to ensure that the toggle has aria-expanded set to "false" if it's not already set explicitly to "true".

Then using the toggle and menu's IDs, the menu's aria-labelledby is set to the toggle's ID, and the toggle's aria-owns is set to the menu's ID.