Focus Manager Node Plugin: Accessible Menu Button
This example illustrates how to use the Focus Manager Node Plugin, Event's delegation support and mouseenter event, along with the Overlay widget and Node's support for the WAI-ARIA Roles and States to create an accessible menu button.
Setting Up the HTML
For a menu button, start with an <a> element whose
href attribute is set to the id of an <div>
that wraps a list of <input> elements.
Therefore, without JavaScript and CSS, the menu button is simply an in-page
link to a set of additional buttons.
Progressive Enhancement
The markup above will be transformed into a menu button widget using both CSS and JavaScript. To account for the scenario where the user has CSS enabled in their browser but JavaScript is disabled, the CSS used to style the menu button will be loaded via JavaScript using the built-in loader of the YUI Global Object. Additionally, JavaScript will be used to temporarily hide the menu button markup while the JavaScript and CSS are in the process of loading to prevent the user from seeing a flash unstyled content.
ARIA Support
Through the use of CSS and JavaScript the HTML for the menu button can be transformed into something that looks and behaves like a desktop menu button, but users of screen readers won't perceive it as an atomic widget, but rather simply as a set of HTML elements. However, through the application of the WAI-ARIA Roles and States, it is possible to improve the semantics of the markup such that users of screen readers perceive it as a menu button control.
Keyboard Functionality
The keyboard functionality for the button's menu will be provided by the Focus
Manager Node Plugin. The Focus Manager's
descendants
attribute is set to a value of "input", so that only one menuitem in the
button's menu is in the browser's default tab flow. This allows users
navigating via the keyboard to use the tab key to quickly move into and out of
the menu. Once the menu has focus, the user can move focus among each menuitem
using the up and down arrows keys, as defined by the value of the
keys
attribute. The
focusClass
attribute is used to apply a class of yui-menuitem-active to
the parent <li> of each
<input> when it is focused, making it easy to style the
menuitem's focused state in each of the
A-Grade browsers.
