This tutorial is currently out-of-date, and will soon be replaced. For help with the Keyboard Accessibility plug-in, feel free to email the infusion-users list with any questions.
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 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:
- 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 accessibility 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:
You'll also want to link to the FSS style sheets to get a tab-like appearance:
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:
(This made use of the following FSS files: fss-layout.css, fss-theme-mist.css)
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 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:
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.
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 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 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 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 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.