Navigation Menu Button Example
This example demonstrates the menu button design pattern for a button that displays a menu of link targets. The menu items are made from HTML links and maintain their HTML link behaviors. That is, activating a menuitem loads the link target, and the browser's link context menu and associated actions are available.
In this implementation, an HTML button element reveals a menu structure made with an HTML ul element.
The menuitem role is on the HTML a element contained by each li element so link behaviors are available when focus is set on the menu item.
Another reason the menuitem role is not on the li element is that the semantics of descendants of ARIA menuitem elements are not exposed in the accessibility tree.
That is, an item in a menu can only be a menuitem because accessibility APIs do not enable assistive technologies to render elements contained inside of an item in a menu.
For a more detailed description of this constraint, see
Roles That Automatically Hide Semantics by Making Their Descendants Presentational.
Similar examples include:
- Action Menu Button Example Using element.focus(): A button that opens a menu of actions or commands where focus in the menu is managed using
element.focus(). - Action Menu Button Example Using aria-activedescendant: A button that opens a menu of actions or commands where focus in the menu is managed using aria-activedescendant.
Example
Keyboard Support
Menu Button
| Key | Function |
|---|---|
| Down Arrow Space Enter |
Opens menu and moves focus to first menuitem |
| Up Arrow | Opens menu and moves focus to last menuitem |
Menu
| Key | Function |
|---|---|
| Enter |
|
| Escape |
|
| Up Arrow |
|
| Down Arrow |
|
| Home | Moves focus to the first menu item. |
| End | Moves focus to the last menu item. |
| A-Z a-z |
|
Role, Property, State, and Tabindex Attributes
Menu Button
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-haspopup="true" |
button
|
|
|
aria-controls="IDREF" |
button
|
|
|
aria-expanded="true" |
button |
|
Note
The label for the button is provided by the text content of the button element.
Menu
| Role | Attribute | Element | Usage |
|---|---|---|---|
menu
|
ul
|
Identifies the ul element as a menu. |
|
|
aria-labelledby="IDREF" |
ul
|
|
none
|
li
|
|
|
menuitem
|
a
|
|
|
tabindex="-1" |
a
|
removes the a element from the page tab sequence but keeps it focusable with JavaScript. |
Javascript and CSS Source Code
- CSS: MenubuttonLinks.css
- Javascript: Menubutton2.js
- Javascript: MenuItemLinks.js
- Javascript: PopupMenuLinks.js
HTML Source Code