YUI 3.x Home -

YUI Library Examples: Focus Manager Node Plugin: Accessible TabView

Note: This is YUI 3.x. Looking for YUI 2.x?

Focus Manager Node Plugin: Accessible TabView

This example illustrates how to create an accessible tabview widget using the Focus Manager Node Plugin, Event's delegation support, and Node's support for the WAI-ARIA Roles and States.

Today's News

Top Stories

World News

Entertainment News

Sports News

Technology News

Setting Up the HTML

The tabs in the tabview widget will be represented by a list of <a> elements whose href attribute is set to the id of an <div> element that contains its content. Therefore, without JavaScript and CSS, the tabs function as in-page links.

For this example the content of each tab panel is created on the server using the YQL API to fetch the title and URL for news stories made available from the various Yahoo! News RSS feeds. Here's the PHP:

Progressive Enhancement

The markup above will be transformed into a tabview 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 tabview will be loaded via JavaScript using the built-in loader of the YUI Global Object. Additionally, JavaScript will be used to temporarily hide the tabview 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 tabview can be transformed into something that looks and behaves like a desktop tab control, 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 tab control.

Keyboard Functionality

The keyboard functionality for the tabview widget will be provided by the Focus Manager Node Plugin. The Focus Manager's descendants attribute is set to a value of ".yui-tab>a", so that only one tab in the tabview 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 tabview. Once the tabview has focus, the user can move focus among each tab using the left and right arrows keys, as defined by the value of the keys attribute. Lastly, the focusClass attribute is used to apply a class of yui-tab-focus to the parent <li> of each <a> when it is focused, making it easy to style the tab's focused state in each of the A-Grade browsers.

Accessibility Sugar

One of the challenges faced by users of screen readers is knowing when you've left the context of a given control. In the case of this tabview, if it were adjacent to another ARIA-enabled widget, the user would know they've left the tabview when the screen reader announces the role of the adjacent widget. However, if the tabview is sitting alongside standard HTML content, it would be really difficult for the user to know when they've left the context of the active panel.

One solution to this problem is to add some additional navigation as the last child of each tab panel that allows the user to move to the previous and next panel in the tabview. This will not only help alert users of screen readers that they've reached the end of the tab's panel, but allow all keyboard users to move more quickly to the next/previous panel. Without this additionally navigation, keyboard users would typically have to press shift+tab to navigate back up to the list of tabs to move to the next/previous tab.

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings