Skip to content
Permalink
Browse files

Menu: Handle SPACE same as ENTER, select items or opening submenus

  • Loading branch information...
jzaefferer committed May 22, 2012
1 parent 1f16138 commit 9dcd0e0eb824a4000692b6ce6d864056339ac498
Showing with 29 additions and 9 deletions.
  1. +14 −2 tests/unit/menu/menu_events.js
  2. +15 −7 ui/jquery.ui.menu.js
@@ -208,7 +208,7 @@ test("handle keyboard navigation on menu without scroll and without submenus", f
});

asyncTest("handle keyboard navigation on menu without scroll and with submenus", function() {
expect(14);
expect(16);
var element = $('#menu2').menu({
select: function(event, ui) {
log($(ui.item[0]).text());
@@ -290,11 +290,23 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)");

log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } );
setTimeout( menukeyboard4, 50 );
}

function menukeyboard4() {
equal( $("#log").html(), "0,keydown,", "Keydown SPACE (open submenu)");

log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)");

log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( menukeyboard5, 50 );
}

function menukeyboard5() {
equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");

log("keydown",true);
@@ -202,13 +202,11 @@ $.widget( "ui.menu", {
event.preventDefault();
break;
case $.ui.keyCode.ENTER:
if ( !this.active.is( ".ui-state-disabled" ) ) {
if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
this.expand( event );
} else {
this.select( event );
}
}
this._activate( event );
event.preventDefault();
break;
case $.ui.keyCode.SPACE:
this._activate( event );
event.preventDefault();
break;
case $.ui.keyCode.ESCAPE:
@@ -260,6 +258,16 @@ $.widget( "ui.menu", {
}
},

_activate: function( event ) {
if ( !this.active.is( ".ui-state-disabled" ) ) {
if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
this.expand( event );
} else {
this.select( event );
}
}
},

refresh: function() {
// initialize nested menus
var menus,

0 comments on commit 9dcd0e0

Please sign in to comment.
You can’t perform that action at this time.