Menu Button with Actions Menu: Implementation Details

This example illustrates the creation of custom menu button, popup menu and menu item widgets that implement the keyboard interactions and utilize the ARIA roles, properties and states specified by the WAI-ARIA Authoring Practices 1.1.

HTML Markup / ARIA

The HTML file for this example is example-actions.html.

button element

ARIA role, properties and states

ul element

ARIA role, properties and states

li elements

ARIA role, properties and states

Scripting

The JavaScript object model for this example contains three objects: MenuButton, PopupMenu and MenuItemAgent, each of which is described below.

MenuButton

Related objects

Keyboard Event Listeners & Behavior

EventKeyBehaviorPrevent Default
keydown Space / Return Open menu; set focus to first item yes
keydown Down Arrow Open menu; set focus to first item yes
keydown Up Arrow Open menu; set focus to last item yes

Mouse Event Listeners & Behavior

EventBehaviorPrevent Default
mouseover Open menu no
mouseout Close menu no
click Open menu; set focus to first item no

PopupMenu

Related objects

Mouse Event Listeners & Behavior

EventBehaviorPrevent Default
mouseover Save hover state (affects whether menu is closed by other means) no
mouseout Conditionally close menu no

Note: Whether the PopupMenu's mouseout event handler closes the menu depends on (a) the focus state of its menuitem elements and (b) the hover state of its controller element.

MenuItemAgent

Related objects

Focus Event Listeners & Behavior

EventBehaviorPrevent Default
focus Save focus state in menu object no
blur Save focus state in menu object no

Keyboard Event Listeners & Behavior

EventKeyBehaviorPrevent Default
keydown Space / Return Generate click event (see mouse click behavior) yes
keydown Escape Set focus to controller element; close menu yes
keydown Tab Set focus to controller element; close menu; Note: Because the handler does not 'Prevent Default', the browser also handles the keydown tab event. no
keydown Down Arrow Set focus to next item (wraps) yes
keydown Up Arrow Set focus to previous item (wraps) yes
keydown Home / Page Up Set focus to first item yes
keydown End / Page Down Set focus to last item yes
keypress Any Printable Character Set focus to item with matching first character no

Mouse Event Listeners & Behavior

EventBehaviorPrevent Default
click Set focus to menu's controller element; close menu no