]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Only focus menu after click if focus is on an element within menu. Fixes #9044...
authorKris Borchers <kris.borchers@gmail.com>
Mon, 26 Aug 2013 05:06:44 +0000 (00:06 -0500)
committerScott González <scott.gonzalez@gmail.com>
Tue, 26 Nov 2013 20:04:39 +0000 (15:04 -0500)
(cherry picked from commit 485e0a06121d712bccad82a21a9e443292d2f9bb)

tests/unit/menu/menu_core.js
ui/jquery.ui.menu.js

index 5ee28c14aa166794e31c0043ecd8ef7bf18110fd..923d2961e8a4ef5583381a46a49d8bb875e59580 100644 (file)
@@ -27,4 +27,22 @@ test( "accessibility", function () {
        // Item roles are tested in the role option tests
 });
 
+asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", function() {
+       expect( 1 );
+       var element = $( "#menu1" ).menu();
+
+       $( "<input>", { id: "test9044" } ).appendTo( "body" );
+
+       $( "#testID1" ).bind( "click", function() {
+               $( "#test9044" ).focus();
+       });
+
+       TestHelpers.menu.click( element, "3" );
+       setTimeout( function() {
+               equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" );
+               $( "#test9044" ).remove();
+               start();
+       });
+});
+
 })( jQuery );
index 8cb2f8ed2bb5c788410bb23991f82e5f9e640b24..bbcc244db23ed11afaa432530ed639feaab9ac72 100644 (file)
@@ -85,7 +85,8 @@ $.widget( "ui.menu", {
                                        // Open submenu on click
                                        if ( target.has( ".ui-menu" ).length ) {
                                                this.expand( event );
-                                       } else if ( !this.element.is( ":focus" ) ) {
+                                       } else if ( !this.element.is( ":focus" ) && $( this.document[ 0 ].activeElement ).closest( ".ui-menu" ).length ) {
+
                                                // Redirect focus to the menu
                                                this.element.trigger( "focus", [ true ] );