Editor Menubar Example: Menuitemradio and Menuitemcheckbox

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

Following is the implementations of the design pattern for menubar that demonstrate how a menubar can be used for actions. Each item in the menubars represents a CSS styling and opens pull down menu items that change the styling of the text. This example also demonstrates the usage of menuitemradio and menuitemcheckbox.

Examples

Menubar With ARIA Markup with menuitemradio and menuitemcheckbox


More information on Gettysburg Address

Notes

  1. List of pull down menu items that change the styling of the text.
  2. Menuitems include radio buttons and checkboxes to indicate the state of the styling of the text.
  3. Font "Size" menu included two menuitems that are disabled base on the current size of the text.

Menubar Widget Implementation Information

Implementation Notes

Keyboard Support

Key Function
Space or Enter Key
  • Opens or closes popup menu.
  • Focus stays on menubar menu item.
Left Arrow Key
  • Moves focus to previous menubar menu item.
  • If focus on first menubar menu item, focus is moved to last menubar menu item.
Right Arrow Key
  • Moves focus to next menubar menu item.
  • If focus on last menubar menu item, focus is moved to first menubar menu item.
Down Arrow Key
  • Opens popup menu.
  • Moves focus to first popup menu item.
Up Arrow Key
  • Opens popup menu.
  • Moves focus to last popup menu item.
Home
  • Moves focus to first menubar menu item.
End
  • Moves focus to last menubar menu item.
Character Key
  • Moves focus to next menubar item that starts with that letter.
  • If no menubar menu item starts with the letter, focus does not move.

Role, Property, State, and Tabindex Attributes

Role Attribute Element Usage
menubar ul
  • The role="menubar" identifies the ul element as a container for set of menuitem widgets associated with the menubar.
  • No tabindex value is needed since the ul[role="menubar"] does not receive keyboard focus.
  • Accessible name for the menu is defined by the aria-label attribute.
aria-label="string" ul
  • Defines an acessible name for the menubar.
  • Used to help people understand the purpose of the menubar and uniquely identify the menubar from other menubars on the page.
menuitem li
  • The role="menuitem" identifies the li element a ARIA menuitem in the menubar widget.
  • Accessible name for the menuitem is defined by the aria-label attribute.
aria-label="string" li
  • Defines an acessible name for the menuitem.
  • Used to help people understand the purpose of the menuitem and uniquely identify the menuitem from other menuitems in the menubar.
tabindex="-1" li
  • Makes the li[role="menuitem"] element keyboard focusable, but not part of tab order of the page.
tabindex="0" li
  • Makes the li[role="menuitem"] element keyboard focusable and part of tab order of the page.
  • Only one menuitem in the menubar has tabindex="0".
  • The default menuitem in the menubar with tabindex="0" is the first menubar item (e.g when page is loaded).
  • The last menubar item to have focus is given the tabindex="0" so that when user tabs through the page focus will be given to the last menubar item that the user used.
aria-haspopup="true" li
  • Identifies the menuitem as having a popup menu.
  • The only function of a menuitem in a menubar is to open and close the popup menu, it cannot be a link or have other actions.
aria-expanded="true" li
  • Indicates popup menu is open.
aria-expanded="false" li
  • Indicates popup menu is closed.

Keyboard Support

Key Function
Space or Enter Key
  • Executes "onclick" action (e.g. bolding text, changing font).
Escape Key
  • Closes popup menu.
  • Moves focus to current menubar menu item.
Left Arrow Key
  • Closes popup menu.
  • Moves focus to previous menubar menu item.
Right Arrow Key
  • Closes popup menu.
  • Moves focus to next menubar menu item.
Up Arrow Key
  • Moves focus to previous popup menu item.
  • If first popup menu item, focus is moved to the last popup menu item.
Down Arrow Key
  • Moves focus to next popup menu item.
  • If last popup menu item, focus is moved to the first popup menu item.
Home
  • Moves focus to first popup menu item.
End
  • Moves focus to last popup menu item.
Character Key
  • Moves focus to the next popup item that starts with that letter.
  • If no popup menu item starts with the letter, focus does not move.

Role, Property, State, and Tabindex Attributes

Role Attribute Element Usage
menu ul
  • The role="menu" identifies the ul element as a container for set of menuitem widgets associated with the menu.
  • No tabindex value is needed since the ul[role="menu"] does not receive keyboard focus.
  • Accessible name for the menu is defined by the aria-label attribute and in the case of a popup menu in a menubar the acessible name is same as the associated menubar item.
aria-label="string" ul
  • Defines an acessible name for the menu.
  • Used to help people understand the purpose of the menu and uniquely identify the menu from other menus in the menubar.
menuitem span
  • The role="menuitem" identifies the li element as a ARIA menuitem widget.
  • A tabindex=-1 value is needed to make the li[role="menuitem"] keyboard focusable.
  • Accessible name for the menu is defined by the aria-label attribute and in the case of a popup menu in a menubar the acessible name is same as the associated menubar item.
tabindex="-1" li
  • Makes li[role="menuitem"], li[role="menuitemcheckbox"] and li[role="menuitemradio"] elements keyboard focusable, but not part of tab order of the page.
  • The li[role="menuitem"], li[role="menuitemcheckbox"] and li[role="menuitemradio"] elements in a popup menu do not ever get any other value for tabindex.
menuitemcheckbox li
  • The role="menuitemcheckbox" identifies the li element as a ARIA menuitemcheckbox widget.
  • The aria-checked attribute is used to indicate if the menuitem checkbox is checked or not.
  • The accessible name comes from the child text content of the li element.
aria-checked="true" li
  • Indicates if a menuitemcheckbox or menuitemradio is checked.
  • The visual state of the selection is synchronized with the aria-checked value using CSS attribute selectors (e.g. [aria-checked="true"]) and the CSS psuedo selector :before and content property.
aria-checked="false" li
  • Indicates if a menuitemcheckbox or menuitemradio is not checked.
  • The visual state of the selection is synchronized with the aria-checked value using CSS attribute selectors (e.g. [aria-checked="false"]) and the CSS psuedo selector :before and content property.
group ul
  • The role="group" identifies the ul element as a container for set of menuitemradio widgets.
  • The group role is important to allow the browser to compute the values of aria-setsize and aria-posinset.
  • No tabindex value is needed since the ul[role="group"] does not receive keyboard focus.
  • Accessible name is not required for ul[role="group"].
menuitemradio li
  • The role="group" identifies the li element as a menuitemradio widgets.
  • Only one menuitemradio item in the same radio button group can be checked at a time.
  • In this example the group is defined by either the ul[role="menu"] or [role="group"].
  • The accessible name comes from the child text content of the li element.

Javascript and CSS Source Code

HTML Source Code

Example: Menubar With ARIA Markup in the HTML Source