Skip to content

Commit 877bcd7

Browse files
author
Rafael J. Staib
committed
Add WAI-ARIA support for pagination
1 parent eb6d0f8 commit 877bcd7

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

demo/css/jquery.steps.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
/* Accessibility */
23-
.wizard > .steps .current-info
23+
.wizard .audible
2424
{
2525
position: absolute;
2626
left: -999em;
@@ -105,9 +105,9 @@
105105
width: 600px;
106106
}
107107

108-
.wizard > .actions a.disabled
108+
.wizard > .actions [aria-disabled="true"] a
109109
{
110-
background: #ccc;
110+
color: #aaa;
111111
}
112112

113113
.wizard > .loading

jquery.steps.js

+47-29
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
* - Jump from any page to a specific step (via uri hash tag test.html#steps-uid-1-3)
2929
* - Add Swipe gesture for devices that support touch
3030
* - Allow clicking on the next step even if it is disabled (so that people can decide whether they use prev button or the step button next to the current step)
31+
* - Property to set the step orientation (horizontal/vertical) [stepOrientation: "horizontal" v 0]
3132
*
3233
*/
3334

3435
/**
3536
* @module jQuery.steps
3637
* @requires jQuery (always required), jQuery.cookie (only required if saveState is `true`)
3738
*/
38-
(function ($)
39+
;(function ($, undefined)
3940
{
41+
"use strict";
42+
4043
/**
4144
* A global unique id count.
4245
*
@@ -487,6 +490,17 @@
487490
**/
488491
current: "current step:",
489492

493+
/**
494+
* This label is important for accessability reasons and describes the kind of navigation.
495+
*
496+
* @property pagination
497+
* @type String
498+
* @default "Pagination"
499+
* @for defaults
500+
* @since 0.9.7
501+
**/
502+
pagination: "Pagination",
503+
490504
/**
491505
* Label for the finish button.
492506
*
@@ -776,6 +790,7 @@
776790
**/
777791
function initialize(options)
778792
{
793+
/*jshint -W040 */
779794
var opts = $.extend(true, {}, $.fn.steps.defaults, options);
780795

781796
return this.each(function (i)
@@ -964,11 +979,12 @@
964979
{
965980
var options = wizard.data("options"),
966981
state = wizard.data("state"),
982+
uniqueId = getUniqueId(wizard),
967983
contentWrapper = $(document.createElement(options.contentContainerTag)).addClass("content"),
968984
startIndex = options.startIndex;
969985

970986
contentWrapper.html(wizard.html());
971-
wizard.addClass(options.cssClass).empty().append(contentWrapper);
987+
wizard.attr("role", "application").addClass(options.cssClass).empty().append(contentWrapper);
972988

973989
var stepTitles = contentWrapper.children(options.headerTag),
974990
stepContents = contentWrapper.children(options.bodyTag).addClass("body").hide();
@@ -987,7 +1003,7 @@
9871003
// Tries to load the saved state (step position)
9881004
if (options.saveState && $.cookie)
9891005
{
990-
var savedState = $.cookie(_cookiePrefix + getUniqueId(wizard));
1006+
var savedState = $.cookie(_cookiePrefix + uniqueId);
9911007
// Sets the saved position to the start index if not undefined or out of range
9921008
var savedIndex = parseInt(savedState, 0);
9931009
if (!isNaN(savedIndex) && savedIndex < state.stepCount)
@@ -1025,21 +1041,21 @@
10251041

10261042
if (options.enablePagination)
10271043
{
1028-
var actionCollection = $(document.createElement("ul")),
1044+
var actionCollection = $("<ul role=\"menu\" aria-label=\"" + options.labels.pagination + "\"></ul>"),
10291045
actionWrapper = $(document.createElement(options.actionContainerTag))
10301046
.addClass("actions").append(actionCollection);
10311047
wizard.append(actionWrapper);
10321048

10331049
if (!options.forceMoveForward)
10341050
{
1035-
actionCollection.append($("<li><a href=\"#previous\">" + options.labels.previous + "</a></li>"));
1051+
actionCollection.append($("<li><a href=\"#previous\" role=\"menuitem\">" + options.labels.previous + "</a></li>"));
10361052
}
10371053

1038-
actionCollection.append($("<li><a href=\"#next\">" + options.labels.next + "</a></li>"));
1054+
actionCollection.append($("<li><a href=\"#next\" role=\"menuitem\">" + options.labels.next + "</a></li>"));
10391055

10401056
if (options.enableFinishButton)
10411057
{
1042-
actionCollection.append($("<li><a href=\"#finish\">" + options.labels.finish + "</a></li>"));
1058+
actionCollection.append($("<li><a href=\"#finish\" role=\"menuitem\">" + options.labels.finish + "</a></li>"));
10431059
}
10441060

10451061
refreshActionState(wizard);
@@ -1067,7 +1083,7 @@
10671083
index: index + 1,
10681084
title: header.html()
10691085
}),
1070-
stepItem = $("<li></li>").html("<a href=\"#" + header.attr("id") + "\">" + title + "</a>");
1086+
stepItem = $("<li><a href=\"#" + header.attr("id") + "\">" + title + "</a></li>");
10711087

10721088
if (index === 0)
10731089
{
@@ -1138,12 +1154,14 @@
11381154
*/
11391155
function updateSteps(wizard, index)
11401156
{
1141-
var options = wizard.data("options");
1157+
var options = wizard.data("options"),
1158+
uniqueId = getUniqueId(wizard);
11421159

11431160
for (var i = index; i < wizard.data("state").stepCount; i++)
11441161
{
1145-
var title = $(".content > .title:eq(" + i + ")", wizard).attr("id", getUniqueId(wizard) + "-" + i);
1146-
$(".steps > ol > li:eq(" + i + ") > a", wizard).attr("href", "#" + getUniqueId(wizard) + "-" + i)
1162+
var uniqueStepId = getUniqueId(wizard) + "-" + i,
1163+
title = $(".content > .title:eq(" + i + ")", wizard).attr("id", uniqueStepId);
1164+
$(".steps > ol > li:eq(" + i + ") > a", wizard).attr("href", "#" + uniqueStepId)
11471165
.html(renderTemplate(options.titleTemplate, { index: i + 1, title: title.html() }));
11481166
}
11491167
}
@@ -1163,7 +1181,7 @@
11631181
var options = wizard.data("options"),
11641182
steps = $(".steps li", wizard),
11651183
currentOrNewStep = steps.eq(index),
1166-
currentInfo = $("<span class=\"current-info\">" + options.labels.current + " </span>"),
1184+
currentInfo = $("<span class=\"current-info audible\">" + options.labels.current + " </span>"),
11671185
stepTitles = $(".content > .title", wizard);
11681186

11691187
if (oldIndex != null)
@@ -1179,7 +1197,7 @@
11791197
}
11801198

11811199
/**
1182-
* Refreshs the visualization for the complete action navigation.
1200+
* Refreshs the visualization for the entire pagination.
11831201
*
11841202
* @static
11851203
* @private
@@ -1201,52 +1219,52 @@
12011219
var previous = $(".actions a[href$='#previous']", wizard).parent();
12021220
if (state.currentIndex > 0)
12031221
{
1204-
previous.removeClass("disabled");
1222+
previous.removeClass("disabled").attr("aria-disabled", "false");
12051223
}
12061224
else
12071225
{
1208-
previous.addClass("disabled");
1226+
previous.addClass("disabled").attr("aria-disabled", "true");
12091227
}
12101228
}
12111229

12121230
if (options.enableFinishButton && options.showFinishButtonAlways)
12131231
{
12141232
if (state.stepCount === 0)
12151233
{
1216-
finish.addClass("disabled");
1217-
next.addClass("disabled");
1234+
finish.addClass("disabled").attr("aria-disabled", "true");
1235+
next.addClass("disabled").attr("aria-disabled", "true");
12181236
}
12191237
else if (state.stepCount > 1 && state.stepCount > (state.currentIndex + 1))
12201238
{
1221-
finish.removeClass("disabled");
1222-
next.removeClass("disabled");
1239+
finish.removeClass("disabled").attr("aria-disabled", "false");
1240+
next.removeClass("disabled").attr("aria-disabled", "false");
12231241
}
12241242
else
12251243
{
1226-
finish.removeClass("disabled");
1227-
next.addClass("disabled");
1244+
finish.removeClass("disabled").attr("aria-disabled", "false");
1245+
next.addClass("disabled").attr("aria-disabled", "true");
12281246
}
12291247
}
12301248
else
12311249
{
12321250
if (state.stepCount === 0)
12331251
{
1234-
finish.hide();
1235-
next.show().addClass("disabled");
1252+
finish.hide().attr("aria-hidden", "true");
1253+
next.show().attr("aria-hidden", "false").addClass("disabled").attr("aria-disabled", "true");
12361254
}
12371255
else if (state.stepCount > (state.currentIndex + 1))
12381256
{
1239-
finish.hide();
1240-
next.show().removeClass("disabled");
1257+
finish.hide().attr("aria-hidden", "true");
1258+
next.show().attr("aria-hidden", "false").removeClass("disabled").attr("aria-disabled", "false");
12411259
}
12421260
else if (!options.enableFinishButton)
12431261
{
1244-
next.addClass("disabled");
1262+
next.addClass("disabled").attr("aria-disabled", "true");
12451263
}
12461264
else
12471265
{
1248-
finish.show();
1249-
next.hide().addClass("disabled");
1266+
finish.show().attr("aria-hidden", "false");
1267+
next.hide().attr("aria-hidden", "true");
12501268
}
12511269
}
12521270
}
@@ -1452,7 +1470,7 @@
14521470
}
14531471

14541472
/**
1455-
* Handles the keyup DOM event.
1473+
* Handles the keyup DOM event for pagination.
14561474
*
14571475
* @static
14581476
* @private

0 commit comments

Comments
 (0)