]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Handle SPACE same as ENTER, select items or opening submenus
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 22 May 2012 14:01:40 +0000 (16:01 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 22 May 2012 14:01:40 +0000 (16:01 +0200)
tests/unit/menu/menu_events.js
ui/jquery.ui.menu.js

index 4cb083240b034719eb2302a56543838287c7cb0f..643da4a26b63aeea2ee652ccec493677d06c6830 100644 (file)
@@ -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);
index d3c32e3a0c206f48616ee51c4ab93f340f874c3a..1bfd767160a5186da030a3686a68c5be13c85021 100644 (file)
@@ -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,