Skip to content

Latest commit

 

History

History
77 lines (54 loc) · 5.02 KB

File metadata and controls

77 lines (54 loc) · 5.02 KB

DisclosureMenu Class

See WAI ARIA Pracitices Example Disclosure for Navigation Menus for a full explanation on what makes a menu a Disclosure Menu.

Extends all functionality for the BaseMenu class.

Parameters

All Parameters must be contained in a single object.

Paramter Description Type Required Default Value
menuElement The menu element in the DOM. HTMLElement true undefined
menuItemSelector The CSS selector string for menu items. string false "li"
menuLinkSelector The CSS selector string for menu links. string false "a"
submenuItemSelector The CSS selector string for menu items containing submenus. string false ""
submenuToggleSelector The CSS selector string for submenu toggle buttons/links. string false "a"
submenuSelector The CSS selector string for submenus. string false "ul"
controllerElement The element controlling the menu in the DOM. HTMLElement|null false null
containerElement The element containing the menu in the DOM. HTMLElement|null false null
openClass The class to apply when a menu is "open". string|string[]|null false "show"
closeClass The class to apply when a menu is "closed". string|string[]|null false "hide"
isTopLevel A flag to mark the root menu. boolean false false
parentMenu The parent menu to this menu. DisclosureMenu|null false null
isHoverable A flag to allow hover events on the menu. boolean false false
hoverDelay The delay for closing menus if the menu is hoverable (in miliseconds). number false 250

Available Getters

See BaseMenu for a list of inherited getters.

Available Setters

See BaseMenu for a list of inherited setters.

Available Methods

See BaseMenu for a list of inherited methods.

Initialize

The initialize function will run BaseMenu's initialize, as well as sets up the focus, click, hover, keydown, and keyup events through the menu.

handleKeydown

Handles keydown events throughout the menu for proper menu use.

This method exists to assit the handleKeyup method.

  • Adds all keydown listeners listed in BaseMenu.
  • Adds a keydown listener to the menu/all submenus.
    • Blocks propagation on the following keys: "ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft", "Home", "End", "Space", "Enter", and "Escape".

handleKeyup

Handles keyup events throughout the menu for proper menu use.

  • Adds all keyup listeners listed in BaseMenu.

The following keybinding explanations are taken from the WAI ARIA Pracitices Example Disclosure for Navigation Menus:

Key Function
Tab or Shift + Tab Move keyboard focus among top-level buttons, and if a dropdown is open, into and through links in the dropdown.
Space or Enter
  • If focus is on a disclosure button, activates the button, which toggles the visibility of the dropdown.
  • If focus is on a link:
    • If any link has aria-current set, removes it.
    • Sets aria-current="page" on the focused link.
    • Activates the focused link.
Escape If a dropdown is open, closes it and sets focus on the button that controls that dropdown.
Down Arrow or Right Arrow (Optional)
  • If focus is on a button and its dropdown is collapsed, and it is not the last button, moves focus to the next button.
  • if focus is on a button and its dropdown is expanded, moves focus to the first link in the dropdown.
  • If focus is on a link, and it is not the last link, moves focus to the next link.
Up Arrow or Left Arrow (Optional)
  • If focus is on a button, and it is not the first button, moves focus to the previous button.
  • If focus is on a link, and it is not the first link, moves focus to the previous link.
Home (Optional)
  • If focus is on a button, and it is not the first button, moves focus to the first button.
  • If focus is on a link, and it is not the first link, moves focus to the first link.
End (Optional)
  • If focus is on a button, and it is not the last button, moves focus to the last button.
  • If focus is on a link, and it is not the last link, moves focus to the last link.

focusNextChild

Focus the menu's next child.

Unlike BaseMenu, if the currently focussed child in the menu is the last child this method will do nothing.

focusPreviousChild

Focus the menu's last child.

Unlike BaseMenu, if the currently focussed child in the menu is the first child this method will do nothing.