Child pages
  • Tutorial - Keyboard Accessibility Plugin

Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

The Fluid library includes a jQuery Keyboard Accessibility plugin. This plugin allows developers to add keyboard handlers to their code without a lot of extra overhead. This tutorial will walk the reader through an example of using the plugin.

This tutorial assumes that:

  • you are already familiar with HTML, Javascript and CSS
  • you are basically familiar with what the Keyboard Accessibility Plugin is and does
  • now you just want to know how to use it.

For technical API documentation, see Keyboard Accessibility Plugin API.

Tutorial: How to Use the Keyboard Accessibility Plugin


Let's say you are creating a set of tabs using an unordered list. This tutorial will show you how to use the jQuery Keyboard Accessibility Plugin to ensure that your tabs can be used with the keyboard.

There are five basic steps to adding Keyboard Accessibility to your application:

  • Setup
  • Step 1: Prepare your markup
  • Step 2: Write the script
  • Step 3: Add the script to your HTML
  • Step 4: Apply styles

The rest of this tutorial will explain each of these steps in detail.

On This Page
Still need help?

Join the fluid-talk mailing list and ask your questions there.

Setup: Download and install the Fluid Infusion library

  1. Download a copy of the Fluid Infusion component library from:
  2. Unpack the zip file you just downloaded, and place the resulting folder somewhere convenient for your development purposes.
    The folder will have the release number in its name (e.g. infusion-1.4/). The rest of this tutorial will use infusion-1.4 in its examples, but if you downloaded a different version, you'll have to adjust.

Step 1: Prepare the required files

You'll need to create a file, say initalize.js, to contain your code - the script you write to apply keyboard accessibility to your tabs.
If you use the InfusionAll file, then your <head> might look like:

<script type="text/javascript" src="infusion-1.0/InfusionAll.js"></script>
<script type="text/javascript" src="initialize.js"></script>

NOTE that the InfusionAll.js file is minified - all of the whitespace has been removed, so it isn't really human-readable.

If you want to be able to debug the code, you'll want to include each of the required files individually. This would look like this:

<script type="text/javascript" src="infusion-1.0/lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.core.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/plugins/delegate/js/jquery.delegate.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/jquery.keyboard-a11y.js"></script>
<script type="text/javascript" src="initialize.js"></script>

You'll also want to link to the FSS style sheets to get a tab-like appearance:

<link href="infusion-1.0/framework/fss/css/fss-layout.css" rel="stylesheet" type="text/css" />
<link href="infusion-1.0/framework/fss/css/fss-theme-mist.css" rel="stylesheet" type="text/css" />

Step 2: Your markup

You want to make your tabs keyboard accessible. Your markup might look like this (with FSS to give us a quick tab appearance):

<body class="fl-theme-mist">

        <!-- Code for the tabs -->
        <ul id="tabs" class="fl-tabs">
          <li class="fl-tabs-active"><a href="#catsPanel">Cats</a></li>
          <li><a href="#dogsPanel">Dogs</a></li>
          <li><a href="#hamstersPanel">Hamsters</a></li>
          <li><a href="#alligatorsPanel">Alligators</a></li>

        <!-- Code for the tab content panels -->
        <div id="panels">
            <div id="catsPanel">Cats <a href="">meow</a>.</div>
            <div id="dogsPanel">Dogs <a href="">bark</a>.</div>
            <div id="hamstersPanel">Hamsters <a href="">wheel</a>.</div>
            <div id="alligatorsPanel">Alligators <a href="">bite</a>.</div>

In a browser window, this might look something like this:

(This made use of the following FSS files: fss-layout.css, fss-theme-mist.css)

Step 3: Create your script

Remember that initalize.js file we prepared before? We'll use that file to contain your initialization script - the script you write to apply keyboard accessibility to your tabs.

In this file, write a function that enables the list items to be selectable with the arrow keys, and show/hide the appropriate panel, as shown on the right:

    var tabs = $("#tabs");
    tabs.fluid("selectable", {
        selectableSelector : 'li',
        direction: fluid.a11y.orientation.HORIZONTAL,
        onUnselect: function(el){
            // hide the panel we're leaving....
        onSelect : function(el){
            // ...and show the panel we're entering

Let's go through this function in detail, to see what it's doing:


This code ensures that the function doesn't execute until the HTML is fully rendered, so that the mark-up will all be there when necessary.

var tabs = $("#tabs");
tabs.fluid("selectable", {

This code finds the DOM element with an ID of tabs and calls keyboard accessibility "selectable" function (through the fluid plug-in), passing in an object defining the options. We'll go through each of the options below.

selectableSelector : 'li',

The selectableSelector option defines the selector that is used to identify which elements within the tabs element should be selectable. This can be any valid selector. In this example, all of the <li> elements will be made selectable.

direction: fluid.a11y.orientation.HORIZONTAL,

The direction option lets the plug-in know whether your tabs are oriented vertically or horizontally, so that up/down and left/right arrows can be interpeted correctly. By specifying fluid.a11y.orientation.HORIZONTAL, our tabs will be navigated using the left/right arrows.

onUnselect: function(el){
    // hide the panel we're leaving....

The onUnselect option allows you to specify a function that will be executed whenever the user selects something other than the current item. For this tabs tutorial, the unselect function hides the current tab by adjusting its CSS class names, which affect its styling.

onSelect : function(el){
    // ...and show the panel we're entering

The onSelect option allows you to specify a function that will be executed when an item is selected. For this tabs tutorial, the selected tab will be shown by adjusting its CSS class names, which affect its styling.

Since there is no visual cues for keyboard accesssibility, it's important to understand that you need to create those cues to know what is selected and where. In CSS, the most basic approach is to take advantage of the outline border-esque feature, added by default in FSS.

  • No labels