Editor Menubar Example
Important Note About Use of This Example
Note: This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.
- There may be support gaps in some browser and assistive technology combinations, especially for mobile/touch devices. Testing code based on this example with assistive technologies is essential before considering use in production systems.
- The ARIA-AT project plans to provide measurements of this example's assistive technology support by the end of 2020.
- Robust accessibility can be further optimized by choosing implementation patterns that maximize use of semantic HTML and heeding the warning that No ARIA is better than Bad ARIA.
The following example demonstrates using the
menubar design pattern
to provide access to sets of actions.
Each item in the below menubar identifies a category of text formatting actions that can be executed from its submenu.
The submenus also demonstrate menuitemradio
and menuitemcheckbox
elements.
Similar examples include:
- Navigation Menubar Example: A menubar that presents site navigation menus.
Example
Accessibility Features
- Users of assistive technologies can identify which format settings are selected because they are represented by menu item radio and menu item checkbox elements that have a checked state.
- Disabled menu items are demonstrated in the font size menu, which includes two disabled menuitems.
- To help communicate that the arrow keys are available for directional navigation within the menubar and its submenus, a border is added to the menubar container when focus is within the menubar.
- To support operating system high contrast settings, focus is highlighted by adding and removing a border around the menu item with focus.
- The down arrow and checked icons are made compatible with operating system high contrast settings and hidden from screen readers by using the CSS
content
property to render images. - Like desktop menubars, submenus open on mouse hover over a parent item in the menubar only if another submenu is already open. That is, if all submenus are closed, a click on a parent menu item is required to display a submenu. Minimizing automatic popups makes exploring with a screen magnifier easier.
-
In general, moving focus in response to mouse hover is avoided in accessible widgets; it causes unexpected context changes for keyboard users.
However, like desktop menubars, there are two conditions in this example menubar where focus moves in response to hover in order to help maintain context for users who use both keyboard and mouse:
- After a parent menu item in the menubar has been activated and the user hovers over a different parent item in the menubar, focus will follow hover.
- When a submenu is open and the user hovers over an item in the submenu, focus follows hover.
Keyboard Support
Menubar
Key | Function |
---|---|
Space Enter |
Opens submenu and moves focus to first item in the submenu. |
Escape | If a submenu is open, closes it. Otherwise, does nothing. |
Right Arrow |
|
Left Arrow |
|
Down Arrow | Opens submenu and moves focus to first item in the submenu. |
Up Arrow | Opens submenu and moves focus to last item in the submenu. |
Home | Moves focus to first item in the menubar. |
End | Moves focus to last item in the menubar. |
Character |
|
Submenu
Key | Function |
---|---|
Space Enter |
Activates menu item, causing action to be executed, e.g., bold text, change font. |
Escape |
|
Right Arrow |
|
Left Arrow |
|
Down Arrow |
|
Up Arrow |
|
Home | Moves focus to the first item in the submenu. |
End | Moves focus to the last item in the submenu. |
Character |
|
Role, Property, State, and Tabindex Attributes
Menubar
Role | Attribute | Element | Usage |
---|---|---|---|
menubar
|
ul
|
|
|
aria-label="string"
|
ul
|
|
|
menuitem
|
span
|
|
|
tabindex="-1"
|
span
|
Makes the menuitem element keyboard focusable but
not part of the Tab sequence of the page.
|
|
tabindex="0"
|
span
|
|
|
aria-haspopup="true"
|
span
|
Indicates that the menuitem has a submenu.
|
|
aria-expanded="true"
|
span
|
Indicates the menu is open. | |
aria-expanded="false"
|
span
|
Indicates the submenu is closed. |
Submenu
Role | Attribute | Element | Usage |
---|---|---|---|
menu
|
ul
|
|
|
aria-label="string"
|
ul
|
Defines an accessible name for the menu .
|
|
menuitem
|
li
|
|
|
tabindex="-1"
|
li
|
Makes the item focusable but not part of the page tab sequence. | |
aria-disabled="false"
|
li
|
Used on the font size "Smaller" and "Larger" options to indicate they are active. | |
aria-disabled="true"
|
li
|
Used on the font size "Smaller" and "Larger" options to indicate one of the options is not active because the largest or smallest font has been selected. | |
menuitemcheckbox
|
li
|
|
|
tabindex="-1"
|
li
|
Makes the menuitemcheckbox focusable but not part of the page tab sequence. | |
aria-checked="true"
|
li
|
|
|
aria-checked="false"
|
li
|
|
|
separator
|
li
|
|
|
group
|
ul
|
|
|
aria-label="string"
|
ul
|
Provides an accessible name for the group of menu items. | |
menuitemradio
|
li
|
|
|
tabindex="-1"
|
li
|
Makes the menuitemradio focusable but not part of the page tab sequence. | |
aria-checked="true"
|
li
|
|
|
aria-checked="false"
|
li
|
|
Textarea
Role | Attribute | Element | Usage |
---|---|---|---|
aria-label="string"
|
textarea
|
Defines an accessible name for the textarea .
|
Javascript and CSS Source Code
- CSS: menubar-editor.css
- Javascript: menubar-editor.js
- Javascript: style-manager.js
HTML Source Code
<div class="menubar-editor">
<ul role="menubar" aria-label="Text Formatting">
<li role="none">
<span role="menuitem"
aria-haspopup="true"
aria-expanded="false"
tabindex="0">
Font
</span>
<ul role="menu"
data-option="font-family"
aria-label="Font">
<li role="menuitemradio" aria-checked="true">
Sans-serif
</li>
<li role="menuitemradio" aria-checked="false">
Serif
</li>
<li role="menuitemradio" aria-checked="false">
Monospace
</li>
<li role="menuitemradio" aria-checked="false">
Fantasy
</li>
</ul>
</li>
<li role="none">
<span role="menuitem"
aria-haspopup="true"
aria-expanded="false"
tabindex="-1">
Style/Color
</span>
<ul role="menu" aria-label="Style/Color">
<li role="none">
<ul role="group"
data-option="font-style"
aria-label="Font Style">
<li role="menuitemcheckbox"
data-option="font-bold"
aria-checked="false">
Bold
</li>
<li role="menuitemcheckbox"
data-option="font-italic"
aria-checked="false">
Italic
</li>
</ul>
</li>
<li role="separator"></li>
<li role="none">
<ul role="group"
data-option="font-color"
aria-label="Text Color">
<li role="menuitemradio" aria-checked="true">
Black
</li>
<li role="menuitemradio" aria-checked="false">
Blue
</li>
<li role="menuitemradio" aria-checked="false">
Red
</li>
<li role="menuitemradio" aria-checked="false">
Green
</li>
</ul>
</li>
<li role="separator"></li>
<li role="none">
<ul role="group"
data-option="text-decoration"
aria-label="Text Decoration">
<li role="menuitemradio" aria-checked="true">
None
</li>
<li role="menuitemradio" aria-checked="false">
Overline
</li>
<li role="menuitemradio" aria-checked="false">
Line-through
</li>
<li role="menuitemradio" aria-checked="false">
Underline
</li>
</ul>
</li>
</ul>
</li>
<li role="none">
<span role="menuitem"
aria-haspopup="true"
aria-expanded="false"
tabindex="-1">
Text Align
</span>
<ul role="menu"
data-option="text-align"
aria-label="Text Align">
<li role="menuitemradio" aria-checked="true">
Left
</li>
<li role="menuitemradio" aria-checked="false">
Center
</li>
<li role="menuitemradio" aria-checked="false">
Right
</li>
<li role="menuitemradio" aria-checked="false">
Justify
</li>
</ul>
</li>
<li role="none">
<span role="menuitem"
aria-haspopup="true"
aria-expanded="false"
tabindex="-1">
Size
</span>
<ul role="menu" aria-label="Size">
<li role="menuitem"
data-option="font-smaller"
aria-disabled="false">
Smaller
</li>
<li role="menuitem"
data-option="font-larger"
aria-disabled="false">
Larger
</li>
<li role="separator"></li>
<li>
<ul role="group"
data-option="font-size"
aria-label="Font Sizes">
<li role="menuitemradio" aria-checked="false">
X-Small
</li>
<li role="menuitemradio" aria-checked="false">
Small
</li>
<li role="menuitemradio" aria-checked="true">
Medium
</li>
<li role="menuitemradio" aria-checked="false">
Large
</li>
<li role="menuitemradio" aria-checked="false">
X-Large
</li>
</ul>
</li>
</ul>
</li>
</ul>
<textarea style="font-size: medium; font-family: sans-serif" aria-label="Text Sample">
Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow, this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us, that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion, that we here highly resolve that these dead shall not have died in vain, that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.
</textarea>
</div>
<p>
<a href="https://en.wikipedia.org/wiki/Gettysburg,_Pennsylvania">
More information on
Gettysburg Address
</a>
</p>