Skip to content

Editor Menubar Example

Editor Menubar Example

Read This First

The code in this example is not intended for production environments. Before using it for any purpose, read this to understand why.

This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.

About This Example

The following example demonstrates using the Menubar Pattern to provide access to editing actions for a text area. Each item in the menubar identifies a category of text formatting actions that can be executed from its submenu. The submenus demonstrate menuitemradio and menuitemcheckbox elements.

Similar examples include:

  • Toolbar Example: A text formatting toolbar that uses roving tabindex to manage focus and contains several types of controls, including toggle buttons, radio buttons, a menu button, a spin button, a checkbox, and a link.
  • Navigation Menubar Example: A menubar that presents site navigation menus.

Example

More information on Gettysburg Address

Accessibility Features

  • Disabled menu items are demonstrated in the font size menu. If the font is set to its smallest size, the Smaller menu item is disabled. Similarly, if the font is set to its largest size, the Larger menu item is disabled.
  • Users of assistive technologies can identify the currently active format options because they are represented by menu item radio and menu item checkbox elements that have a checked state.
  • To prevent the character entities that visually represent The down arrow and checked icons from being announced by screen readers, they are hidden from the accessible name computation with the aria-hidden attribute.
  • 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.
  • Like most 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 triggered by hover 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.
  • To support operating system high contrast settings, focus is highlighted by adding and removing a border around the menu item with focus.

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
  • 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
aria-label="string" ul
  • Defines an accessible 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 span
  • Identifies the element as a menu item within the menubar.
  • Accessible name comes from the text content.
tabindex="-1" span Makes the menuitem element keyboard focusable but not part of the Tab sequence of the page.
tabindex="0" span
  • 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 the practice for Managing Focus Within Components Using a Roving tabindex.
aria-haspopup="true" span Indicates that the menuitem has a submenu.
aria-expanded="true" span
  • Indicates the submenu is open.
  • The visual appearance of the expanded state is synchronized with the aria-expanded value using CSS attribute selectors and hidden from screen readers with aria-hidden="true".
aria-expanded="false" span
  • Indicates the submenu is closed.
  • The visual appearance of the expanded state is synchronized with the aria-expanded value using CSS attribute selectors and hidden from screen readers with aria-hidden="true".
aria-hidden="true" span Removes the character entities used to represent the down arrow icons for parent menu items from the accessibility tree to prevent them from being included in the accessible name of the menu item.

Submenu

Role Attribute Element Usage
menu ul
aria-label="string" ul Defines an accessible name for the menu.
menuitem li
  • Identifies the element as an item in the submenu.
  • Accessible name comes from the text content.
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
  • Identifies the element as a menuitemcheckbox.
  • Accessible name comes from the text content.
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 and hidden from screen readers with aria-hidden="true".
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 and hidden from screen readers with aria-hidden="true".
aria-hidden="true" span Removes the character entities that visually represent the checked state of menuitemcheckbox elements from the accessibility tree to prevent them from being included in the accessible name of the menu item.
separator li
  • Identifies the element as a visual separator between groups of items within a menu, such as groups of menuitemradio or menuitemcheckbox elements.
  • Is not focusable but may be perceivable by a screen reader user when using a reading cursor that does not depend on focus.
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.
aria-label="string" ul Provides an accessible name for the group of menu items.
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.
  • Accessible name is computed from the text content.
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 and hidden from screen readers with aria-hidden="true".
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 and hidden from screen readers with aria-hidden="true".
aria-hidden="true" span Removes the character entities that visually represent the checked state of menuitemradio elements from the accessibility tree to prevent them from being included in the accessible name of the menu item.

Textarea

Role Attribute Element Usage
aria-label="string" textarea Defines an accessible name for the textarea.

Javascript and CSS Source Code

HTML Source Code

Back to Top

This is an unpublished draft preview that might include content that is not yet approved. The published website is at w3.org/WAI/.