Actions Menu Button Example
This example implements the menu button design pattern
for a button that provides access to a menu of actions.
When an element with role button
has aria-haspopup="true"
,
browsers inform assistive technologies that the button is a menu button.
This role transformation caused by aria-haspopup
happens with any element that is recognized as a button,
including the HTML button
and input[type="button"]
elements.
Similar examples include:
- Navigation Menu Button: The popup menu items are
a
elements and act as links.
Example
This example shows a popup menu of actions that can be used for changing states in a web application.
Keyboard Support
Menu Button
Key | Function |
---|---|
Down Arrow, Space, or Enter |
Open menu and move focus to first menuitem |
Up Arrow Key | Open menu and move focus to previous menuitem |
Popup Menu Widget
Key | Function |
---|---|
Space or Enter |
|
Escape |
|
Up Arrow |
|
Down Arrow |
|
Home |
|
End |
|
A-Z, a-z |
|
Role, Property, State, and Tabindex Attributes
Menu Button Widget
Role | Attribute | Element | Usage |
---|---|---|---|
button
|
button
|
|
|
|
aria-haspopup="true" |
button
|
|
|
aria-controls="IDREF" |
button
|
|
aria-expanded="true" |
button |
|
|
aria-expanded="false" |
button |
|
Popup Menu
Role | Attribute | Element | Usage |
---|---|---|---|
menu
|
ul
|
|
|
|
aria-labelledby="[IDREF]" |
ul
|
|
menuitem
|
li
|
|
|
|
tabindex="-1" |
li
|
|
Javascript and CSS Source Code
- CSS: MenubuttonAction.css
- Javascript: Menubutton.js
- Javascript: MenuItemAction.js
- Javascript: PopupMenuAction.js
HTML Source Code
<div id="ex1">
<p>
This example shows a popup menu of actions that can be used for changing states in a web application.
</p>
<div class="menu_button">
<button id="menubutton1"
aria-haspopup="true"
aria-expanded="false"
aria-controls="menu1">
Actions
</button>
<ul id="menu1"
role="menu"
aria-labelledby="menubutton1">
<li role="menuitem" onclick="updateLastAction(event)">
Action 1
</li>
<li role="menuitem" onclick="updateLastAction(event)">
Action 2
</li>
<li role="menuitem" onclick="updateLastAction(event)">
Action 3
</li>
<li role="menuitem" onclick="updateLastAction(event)">
Action 4
</li>
</ul>
</div>
<p>
<label>
Last Action:
<input id="action_output"
type="text"
value="">
</label>
</p>
<script type="text/javascript">
document.getElementById("action_output").value = "none"; function updateLastAction(event) { document.getElementById("action_output").value = event.currentTarget.innerHTML; } window.onload=function() { var menubutton = new Menubutton(document.getElementById('menubutton1')); menubutton.init(); }
</script>
</div>