Editor Menubar Example

NOTE: Please provide feedback on this example in issue 409.

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:

Example


More information on Gettysburg Address

Accessibility Features

  1. 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.
  2. Disabled menu items are demonstrated in the font size menu, which includes two disabled menuitems .
  3. The down arrow and checked icons are made compatible with high contrast mode and hidden from screen readers by using the CSS content property to render images.

Keyboard Support

Menubar

Key Function
Space
Enter
Opens submenu and moves focus to first item in the submenu.
Right Arrow
  • Moves focus to the next item in the menubar.
  • If focus is on the last item, moves focus to the first item.
Left Arrow
  • Moves focus to the previous item in the menubar.
  • If focus is on the first item, moves focus to the last item.
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
  • Moves focus to next item in the menubar having a name that starts with the typed character.
  • If none of the items have a name starting with the typed character, focus does not move.

Submenu

Key Function
Space
Enter
Activates menu item, causing action to be executed, e.g., bold text, change font.
Escape
  • Closes submenu.
  • Moves focus to parent menubar item.
Right Arrow
  • Closes submenu.
  • Moves focus to next item in the menubar.
  • Opens submenu of newly focused menubar item, keeping focus on that parent menubar item.
Left Arrow
  • Closes submenu.
  • Moves focus to previous item in the menubar.
  • Opens submenu of newly focused menubar item, keeping focus on that parent menubar item.
Down Arrow
  • Moves focus to the next item in the submenu.
  • If focus is on the last item, moves focus to the first item.
Up Arrow
  • Moves focus to previous item in the submenu.
  • If focus is on the first item, moves focus to the last item.
Home Moves focus to the first item in the submenu.
End Moves focus to the last item in the submenu.
Character
  • Moves focus to the next item having a name that starts with the typed character.
  • If none of the items have a name starting with the typed character, focus does not move.

Role, Property, State, and Tabindex Attributes

Menubar

Role Attribute Element Usage
menubar ul
  • Identifies the element as a menubar container for a set of menuitem elements.
  • Is not focusable because focus is managed using roving tabindex.
aria-label="string" ul
  • Defines an acessible name for the menubar.
  • Helps assistive technology users understand the purpose of the menubar and distinguish it from any other menubars or similar elements on the page.
menuitem li Identifies the element as a menu item within the menubar.
tabindex="-1" li Makes the menuitem element keyboard focusable but not part of the Tab sequence of the page.
tabindex="0" li
  • Makes the menuitem element keyboard focusable and part of the tab sequence of the page.
  • Only one menuitem in the menubar has tabindex="0".
  • When the page loads, the first item in the menubar has tabindex="0".
  • Focus is managed using roving tabindex.
aria-haspopup="true" li Indicates that the menuitem has a submenu.
aria-expanded="true" li Indicates the submenu is open.
aria-expanded="false" li Indicates the submenu is closed.

Submenu

Role Attribute Element Usage
menu ul
  • Identifies the element as a menu container for a set of menuitem elements.
  • Is not focusable because focus is managed using roving tabindex.
aria-label="string" ul Defines an acessible name for the menu.
menuitem li Identifies the element as an item in the submenu.
tabindex="-1" li Makes the item focusable but not part of the page tab sequence.
menuitemcheckbox li Identifies the element as a menuitemcheckbox.
tabindex="-1" li Makes the menuitemcheckbox focusable but not part of the page tab sequence.
aria-checked="true" li
  • Indicates that the menuitemcheckbox is checked.
  • The visual appearance of the selected state is synchronized with the aria-checked value using CSS attribute selectors.
aria-checked="false" li
  • Indicates that the menuitemcheckbox is NOT checked.
  • The visual appearance of the selected state is synchronized with the aria-checked value using CSS attribute selectors.
group ul
  • Identifies the element as a container for a set of menuitemradio elements.
  • Enables browsers to compute values of aria-setsize and aria-posinset.
menuitemradio li
  • Identifies the element as a menuitemradio element.
  • When all items in a submenu are members of the same radio group, the group is defined by the menu element; a group element is not necessary.
tabindex="-1" li Makes the menuitemradio focusable but not part of the page tab sequence.
aria-checked="true" li
  • Indicates the menuitemradio is checked.
  • The visual appearance of the selected state is synchronized with the aria-checked value using CSS attribute selectors.
aria-checked="false" li
  • Indicates that the menuitemradio is NOT checked.
  • The visual appearance of the selected state is synchronized with the aria-checked value using CSS attribute selectors.

Javascript and CSS Source Code

HTML Source Code