third_party/aria-practices/src/content/patterns/menu-button/examples/menu-button-links.html
This example demonstrates the Menu Button Pattern for a button that displays a menu of link targets. The menu items are made from HTML links, so they 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 for applying the menuitem role to the a element instead of the li element is that the semantics of descendants of 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:
element.focus().WAI-ARIA Quick Links
currentcolor value for the fill and stroke properties of the SVG polygon element is used to synchronize the color with text content. If specific colors are used to specify the fill and stroke properties, these colors will remain the same in high contrast mode, which could lead to insufficient contrast between the icon and the background or even make the icon invisible if its color matches the high contrast mode background.| Key | Function |
|---|---|
| Down Arrow | |
| Space | |
| Enter | Opens menu and moves focus to first menuitem |
| Up Arrow | Opens menu and moves focus to last menuitem |
| Key | Function |
|---|---|
| Space | |
| Enter | Activates the menu item, which is equivalent to activating the link element from which the menu item is made. |
| 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 | Attribute | Element | Usage |
|---|---|---|---|
aria-haspopup="true" | button |
aria-haspopup set to either true or menu as menu buttons.|
| | aria-controls="ID_REFERENCE" | button |
|
| | aria-expanded="false" | button | Indicates the menu is not displayed and that activating the menu button opens the menu. |
| | aria-expanded="true" | button | Indicates the menu is displayed and that activating the menu button closes the menu. |
The label for the button is provided by the text content of the button element.
| Role | Attribute | Element | Usage |
|---|---|---|---|
menu | ul | Identifies the ul element as a menu. | |
| `` | aria-labelledby="ID_REFERENCE" | ul |
menu.|
| none | | li |
listitem role of the li element from assistive technologies.presentation Role.|
| menuitem | | a |
menuitem.a element provides the accessible name of the menuitem.|
| | tabindex="-1" | a | removes the a element from the page tab sequence but keeps it focusable with JavaScript. |
Learn how to interpret and use assistive technology support data
To copy the following HTML code, please open it in CodePen.