The Fluid library includes a jQuery Keyboard Accessibility (a11y) 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 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 four basic steps to adding Keyboard Accessibility to your application:
- 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.
Setup: Download and install the Fluid Infusion library
- Download a copy of the Fluid Infusion component library from:
You only really need the "Minified deployment package," but if you want to actually look at the code, you should download the "Source package."
- 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 a11y to your tabs.
If you use the
InfusionAll file, then your
<head> might look like:
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:
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):
In a browser window, this might look something like this:
Step 3: Create your script
initalize.js file we prepared before? We'll use that file to contain your initialization script - the script you write to apply keyboard a11y 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:
This function says "once the DOM is ready to be traversed, make all the
<LI> elements within the
#tabs container selectable with the left and right arrow keys.
selectableSelector could be any selector, but for the purposes of this tutorial we're interested in the list items themselves.
That's it! That's all you need to do to add keyboard functionality to your document.
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.