Skip to content

Commit

Permalink
remove non-standard use of the aria-expanded attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb committed Feb 19, 2015
1 parent ad76b47 commit 3ff372d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
19 changes: 8 additions & 11 deletions a11yfy/jquery.a11yfy.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,12 @@
.addClass("a11yfy-second-level-menu")
.parent()
.addClass("a11yfy-has-submenu")
.attr("aria-haspopup", "true")
.attr("aria-expanded", "false");
.attr("aria-haspopup", "true");
$this.find(">li>ul>li>ul")
.addClass("a11yfy-third-level-menu")
.parent()
.addClass("a11yfy-has-submenu")
.attr("aria-haspopup", "true")
.attr("aria-expanded", "false");
.attr("aria-haspopup", "true");
/*
* Set up the keyboard and mouse handlers for all the individual menuitems
*/
Expand Down Expand Up @@ -227,7 +225,7 @@
$nextItem.attr("tabindex", "0").focus();
$this.attr("tabindex", "-1");
if ($nextItem.parent().get(0) !== $this.parent().get(0)) {
$this.parent().parent("li").removeClass("open").attr("aria-expanded", "false");
$this.parent().parent("li").removeClass("open");
}
}
e.stopPropagation();
Expand All @@ -248,7 +246,7 @@
*/
function openMenu() {
if($this.hasClass("a11yfy-has-submenu")) {
$this.addClass("open").attr("aria-expanded", "true").find(">ul>li:visible").first().attr("tabindex", "0").focus();
$this.addClass("open").find(">ul>li:visible").first().attr("tabindex", "0").focus();
$this.attr("tabindex", "-1");
}
}
Expand Down Expand Up @@ -329,7 +327,7 @@
if ($this.parent().attr("role") === "menu") {
// this is part of a submenu, set focus on containing li
$this.parent().parent().attr("tabindex", "0").focus()
.removeClass("open").attr("aria-expanded", "false");
.removeClass("open");
$this.attr("tabindex", "-1");
}
}
Expand Down Expand Up @@ -375,9 +373,9 @@
var $this = jQuery(this);

if (!$this.hasClass("open")) {
$this.addClass("open").attr("aria-expanded", "true");
$this.addClass("open");
} else {
$this.removeClass("open").attr("aria-expanded", "false");
$this.removeClass("open");
}
}).first().attr("tabindex", "0"); // Make the first menuitem in the menubar tab focussable
$this.on("keydown", function (e) {
Expand Down Expand Up @@ -415,8 +413,7 @@
if (jQuery(value).parent().hasClass("a11yfy-top-level-menu")) {
jQuery(value).attr("tabindex", "0");
}
}).attr("aria-expanded", "false")
.removeClass("open");
}).removeClass("open");
}, 0);
}
return true;
Expand Down
10 changes: 2 additions & 8 deletions tests/unit/a11yfy/a11yfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
asyncTest("The keyboard and focus functionality", function () {
var $menu = jQuery("#menu-test-2");

expect(42);
expect(38);
$menu.a11yfy("menu");
$menu.find("li").each(function(index, value) {
// Add ids to all the lists so we can track them
Expand Down Expand Up @@ -147,7 +147,6 @@
equal(jQuery(document.activeElement).attr("id"), "test2-6", "Should b in sub-menu");
jQuery(document.activeElement).simulate("keypress", {charCode: 70}); // "f"
equal(jQuery(document.activeElement).attr("id"), "test2-15", "f should go to the last item in the top menu");
equal(jQuery("#test2-6").parent().parent().attr("aria-expanded"), "false", "sub-menu state should be set to not expanded");
equal(jQuery("#test2-6:visible").length, 0, "sub-menu should no longer be visible");
jQuery(document.activeElement).simulate("keydown", {keyCode: 39}); // RIGHT
equal(jQuery(document.activeElement).attr("id"), "test2-0", "Right goes back to the beginning");
Expand All @@ -158,7 +157,6 @@
equal(jQuery(document.activeElement).attr("id"), "test2-5", "Right should get us to the second top level menu item");
jQuery(document.activeElement).simulate("keydown", {keyCode: 40}); // DOWN
equal(jQuery(document.activeElement).attr("id"), "test2-6", "Down on the second top level menu item (with a sub menu) should open it and set focus into it");
equal(jQuery(document.activeElement).parent().parent().attr("aria-expanded"), "true", "When opened, the menu should have aria-expanded set to true");
ok(jQuery(document.activeElement).parent().parent().hasClass("open"), "When opened, the menu should have open class");
jQuery(document.activeElement).simulate("keydown", {keyCode: 27}); // ESC
equal(jQuery(document.activeElement).attr("id"), "test2-5", "ESC should close the sub-menu");
Expand All @@ -184,7 +182,6 @@
// Close sub-sub-menu
jQuery(document.activeElement).simulate("keydown", {keyCode: 27}); // ESC
equal(jQuery(document.activeElement).attr("id"), "test2-6", "ESC should close the sub-sub-menu");
equal(jQuery("#test2-7").parent().parent().attr("aria-expanded"), "false", "aria-expended should be false after close");
ok(!jQuery("#test2-7").parent().parent().hasClass("open"), "open class should be removed after close");
// Open sub-sub-menu
jQuery(document.activeElement).simulate("keydown", {keyCode: 39}); // RIGHT
Expand All @@ -201,7 +198,6 @@

setTimeout(function() {
// These tests are in a timeout to deal with the Firefox bug
equal(jQuery("#test2-6").parent().parent().attr("aria-expanded"), "false", "sub-menu state should be set to not expanded");
equal(jQuery("#test2-6:visible").length, 0, "sub-menu should no longer be visible");
// focus should now go to the parent of the sub-menu previously focussed
$menu.find("li[tabindex=0]").simulate("focus");
Expand Down Expand Up @@ -314,7 +310,7 @@
test("The click to open a menu", function () {
var $menu = jQuery("#menu-testclick");

expect(7);
expect(5);
$menu.a11yfy("menu");
$menu.find("li").each(function(index, value) {
// Add ids to all the lists so we can track them
Expand All @@ -324,11 +320,9 @@
// click the menu to open the sub-menu
$menu.find("li[tabindex=0]").simulate("click");
equal(jQuery("#testclick-1").is(":visible"), true, "Should open menu");
equal(jQuery("#testclick-0").attr("aria-expanded"), "true", "Should have correct state");
equal(jQuery("#testclick-0").hasClass("open"), true, "Should have correct state");
$menu.find("li[tabindex=0]").simulate("click");
equal(jQuery("#testclick-1").is(":visible"), false, "Should open menu");
equal(jQuery("#testclick-0").attr("aria-expanded"), "false", "Should have correct state");
equal(jQuery("#testclick-0").hasClass("open"), false, "Should have correct state");
});

Expand Down

0 comments on commit 3ff372d

Please sign in to comment.