YUI Library Home

YUI Library Examples: TabView Control: Using the TabView ARIA Plugin

TabView Control: Using the TabView ARIA Plugin

The TabView ARIA Plugin makes it easy to use the WAI-ARIA Roles and States with the TabView control. Using the ARIA plugin, a TabView is more interoperable with assistive technologies (AT), such as screen readers, making it more accessible to users with disabilities.

Watch a screen cast of this example running in Firefox 3 with the NVDA screen reader, to see immediately the benefits that ARIA provides, or download the latest development snapshot of NVDA to test this example for yourself.

Getting Started

Using the TabView ARIA Plugin is easy. Simply include the source file(s) for the ARIA plugin after the TabView source files as indicated on the TabView landing page.

1<!-- Source file --> 
2<script type="text/javascript" src="../tabview/assets/tabviewariaplugin.js"></script> 
view plain | print | ?

All YUI ARIA Plugins require the user's browser and AT support the WAI-ARIA Roles and States. Currently only Firefox 3 and Internet Explorer 8 have support for ARIA, and are supported by several screen readers for Windows that also offer support for ARIA. For this reason the YUI ARIA Plugins are only enabled by default for these browsers. To enable the ARIA plugin for other browsers, simply the set the usearia attribute to true. For example:

1var oTabView = new YAHOO.widget.TabView({ usearia: true }); 
view plain | print | ?

Plugin Features

The labelledby and describedby attributes.

The TabView ARIA Plugin adds a labelledby and describedby attribute to the TabView class, each of which maps back to their respective ARIA property of aria-labelledby and aria-describedby.

1var oTabView = new YAHOO.widget.TabView({ usearia: true, labelledby: "tabview-label" }); 
view plain | print | ?

Enhanced Keyboard Support

Out of the box, TabView provides basic keyboard support. Each Tab in a TabView is represented by an <A> element that enables the user to press the tab key or shift-tab to move focus between each TabView. In keeping with the WAI-ARIA Best Practices for keyboard navigation the ARIA plugin for TabView enhances TabView's default behavior such that only one Tab is in the browser's tab index, enabling the user to easily tab into and out of the TabView. When a Tab in a TabView has focus, pressing the arrow keys moves focus between each Tab in the TabView.

Mac vs. Windows

There are two different models for arrow key support for tabbed-content controls in operating systems: Mac OS X and Windows. On Windows, pressing the left or right arrow key moves focus to the next Tab and immediately displays its corresponding TabPanel. On the Mac with VoiceOver enabled, the arrow keys only move focus between each Tab and the user must press the space bar to load the content of the Tab's corresponding TabPanel. The ARIA plugin for TabView implements the Mac's model, as it is better for a DHTML TabView. Since as Tab's content can be loaded via XHR, the Mac's more intentional Tab selection model helps prevent the user from making requests for data he/she is not interested in consuming.

Supporting Multiple Orientations

The orientation attribute of the TabView is used to render the Tabs on any of the widget's four sides. To provide arrow key support that will work regardless of the orientation of the Tabs, the left and up keys will move the focus to the previous Tab, while the right and down arrow keys will move the focus to the next Tab. As an additional convenience to the user, focus is automatically moved to the first or last Tab when the user has reached the beginning or end of a list of Tabs.

Example-Specific Tweaks

First we'll use the labelled attribute to provide some helpful instructional text that will be announced to the user when the TabView initially receives focus. Since each Tab's content is loaded asynchronously, we'll also leverage WAI-ARIA Live Regions to message the user when a Tab's content is both being loaded and has finished loading. The following code snippet illustrates how it all comes together:

1(function() { 
2 
3    var Dom = YAHOO.util.Dom, 
4        UA = YAHOO.env.ua, 
5 
6        oTitle, 
7        oTabViewEl, 
8        oLog, 
9        sInstructionalText; 
10 
11    var oTabView = new YAHOO.widget.TabView(); 
12     
13    oTabView.addTab( new YAHOO.widget.Tab({ 
14        label: 'Opera'
15        dataSrc: 'assets/news.php?query=opera+browser'
16        cacheData: true
17        active: true 
18    })); 
19 
20    oTabView.addTab( new YAHOO.widget.Tab({ 
21        label: 'Firefox'
22        dataSrc: 'assets/news.php?query=firefox+browser'
23        cacheData: true 
24    })); 
25 
26    oTabView.addTab( new YAHOO.widget.Tab({ 
27        label: 'Explorer'
28        dataSrc: 'assets/news.php?query=microsoft+explorer+browser'
29        cacheData: true 
30    })); 
31 
32    oTabView.addTab( new YAHOO.widget.Tab({ 
33        label: 'Safari'
34        dataSrc: 'assets/news.php?query=apple+safari+browser'
35        cacheData: true 
36    })); 
37 
38    oTabView.appendTo('container'); 
39     
40 
41    //  Make use of some additional ARIA Roles and States to further enhance the TabView if the  
42    //  browser supports ARIA. 
43     
44    if ((UA.gecko && UA.gecko >= 1.9) || (UA.ie && UA.ie >= 8)) { 
45 
46        //  Use the "labelledby" attribute provided by the ARIA plugin for TabView to label the  
47        //  TabView with the <h2>, and append some instructional text to the <H2> that tells users  
48        //  of screen readers how to use TabView.  This text will be read when the first Tab is  
49        //  focused.  Since this text is specifically for users of screen readers, it will be  
50        //  hidden off screen via CSS. 
51 
52        oTitle = Dom.get("tabview-title"); 
53 
54        sInstructionalText = oTitle.innerHTML; 
55 
56        oTitle.innerHTML = (sInstructionalText + "<em>Press the space bar or enter key to load the content of each tab.</em>"); 
57 
58        oTabView.set("labelledby""tabview-title"); 
59 
60 
61        //  Since the content of each Tab is loaded via XHR, append a Live Region to the TabView's  
62        //  root element that will be used to message users about the status of each Tab's content.   
63 
64        oTabViewEl = oTabView.get("element"); 
65        oLog = oTabViewEl.ownerDocument.createElement("div"); 
66 
67        oLog.setAttribute("role""log"); 
68        oLog.setAttribute("aria-live""polite"); 
69 
70        oTabViewEl.appendChild(oLog); 
71 
72 
73        //  "activeTabChange" event handler used to notify the screen reader that  
74        //  the content of the Tab is loading by updaing the content of the Live Region. 
75 
76        oTabView.on("activeTabChange"function (event) { 
77 
78            var oTabEl = this.get("activeTab").get("element"), 
79                sTabLabel = oTabEl.textContent || oTabEl.innerText, 
80                oCurrentMessage = Dom.getFirstChild(oLog), 
81                oMessage = oLog.ownerDocument.createElement("p"); 
82 
83            oMessage.innerHTML = "Please wait.  Content loading for " + sTabLabel + " property page."
84 
85            if (oCurrentMessage) { 
86                oLog.replaceChild(oMessage, oCurrentMessage); 
87            } 
88            else { 
89                oLog.appendChild(oMessage);                      
90            } 
91 
92        });  
93     
94 
95        //  "dataLoadedChange" event handler used to notify the screen reader that  
96        //  the content of the Tab has finished loading by updating the content of the Live Region. 
97         
98        var onDataLoadedChange = function (event) { 
99 
100            var oTabEl = this.get("element"), 
101                sTabLabel = oTabEl.textContent || oTabEl.innerText, 
102                oCurrentMessage = Dom.getFirstChild(oLog), 
103                oMessage = oLog.ownerDocument.createElement("p"); 
104 
105            oMessage.innerHTML = "Content loaded for " + sTabLabel + " property page."
106 
107            if (oCurrentMessage) { 
108                oLog.replaceChild(oMessage, oCurrentMessage); 
109            } 
110            else { 
111                oLog.appendChild(oMessage);                      
112            } 
113         
114        }; 
115     
116        oTabView.getTab(0).on("dataLoadedChange", onDataLoadedChange); 
117        oTabView.getTab(1).on("dataLoadedChange", onDataLoadedChange); 
118        oTabView.getTab(2).on("dataLoadedChange", onDataLoadedChange); 
119        oTabView.getTab(3).on("dataLoadedChange", onDataLoadedChange); 
120 
121    } 
122     
123})(); 
view plain | print | ?

Screen Reader Testing

Two of the leading screen readers for Windows, JAWS and Window-Eyes, support ARIA. Free, trial versions of both are available for download, but require Windows be restarted every 40 minutes. The open-source NVDA Screen Reader is the best option for developers as it is both free and provides excellent support for ARIA.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 127ms (+89) 9:14:56 AM:

LogReader instance0

LogReader initialized

INFO 38ms (+0) 9:14:56 AM:

Get

Appending node: ../../../2.x/build/event-mouseenter/event-mouseenter-min.js

INFO 38ms (+1) 9:14:56 AM:

Get

attempting to load ../../../2.x/build/event-mouseenter/event-mouseenter-min.js

INFO 37ms (+26) 9:14:56 AM:

Get

_next: q0, loaded: undefined

INFO 11ms (+0) 9:14:56 AM:

Tab

attributes initialized

INFO 11ms (+0) 9:14:56 AM:

Tab

creating Tab Dom

INFO 11ms (+0) 9:14:56 AM:

Tab

attributes initialized

INFO 11ms (+1) 9:14:56 AM:

Tab

creating Tab Dom

INFO 10ms (+0) 9:14:56 AM:

Tab

attributes initialized

INFO 10ms (+2) 9:14:56 AM:

Tab

creating Tab Dom

INFO 8ms (+1) 9:14:56 AM:

Tab

attributes initialized

INFO 7ms (+1) 9:14:56 AM:

Tab

creating Tab Dom

INFO 6ms (+1) 9:14:56 AM:

TabView

attributes initialized

INFO 5ms (+5) 9:14:56 AM:

TabView

TabView Dom created

INFO 0ms (+0) 9:14:56 AM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

More TabView Control Resources:

Copyright © 2011 Yahoo! Inc. All rights reserved.

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