Navigation Menubar Example
The following implementation of the design pattern for menubar demonstrates a menubar that provides site navigation menus. Each item in the menubar represents a section of a web site for a mythical university and opens a submenu containing menu items that link to pages within that section.
Similar examples include:
- Editor Menubar Example: Example of a menubar that presents text styling actions similar to an editor application.
- Example Disclosure for Navigation Menus: Navigation menus implemented as simple drop down lists of links that are shown and hidden using disclosure buttons.
Example
Accessibility Features
- 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 arrow icons indicating the current state of expandable menus use in-line SVG images with the CSS currentColorvalue for thefillandstrokeproperties of thepolygonelement.
 
- Since the menubar presents a site navigation system, it is wrapped in a navigation region implemented with a navelement that has anaria-labelthat matches the label on the menubar.
Keyboard Support
Menubar
| Key | Function | 
|---|---|
| Space Enter | Opens submenu and moves focus to first item in the submenu. | 
| 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 | 
 | 
| 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 | a | 
 | |
| tabindex="-1" | a | Makes the aelement keyboard focusable, but not part of the tab sequence. | |
| tabindex="0" | a | 
 | |
| aria-haspopup="true" | a | Indicates the menuitem has a submenu. | |
| aria-expanded="true" | a | Indicates the submenu is open. | |
| aria-expanded="false" | a | Indicates the submenu is closed. | |
| none | li | 
 | 
Submenu
| Role | Attribute | Element | Usage | 
|---|---|---|---|
| menu | ul | Identifies the element as a menu container for a set of menu items. | |
| aria-label="string"
             | ul | 
 | |
| menuitem | a | 
 | |
| tabindex="-1" | a | Keeps the aelement focusable but removes it from the Tab sequence. | |
| aria-haspopup="true" | a | Indicates the menu item has a submenu. | |
| aria-expanded="true" | a | Indicates the submenu is open. | |
| aria-expanded="false" | a | Indicates the submenu is closed. | |
| none | li | 
 | 
Javascript and CSS Source Code
- CSS: menubar-navigation.css
- Javascript: menubar-navigation.js
HTML Source Code