Skip to content

Commit

Permalink
Menu: Only focus menu after click if focus is on an element within me…
Browse files Browse the repository at this point in the history
…nu. Fixes #9044 - Menu: Autofocus issue with dialog opened from menu widget

(cherry picked from commit 485e0a0)
  • Loading branch information
kborchers authored and scottgonzalez committed Nov 26, 2013
1 parent 225b693 commit 78c593b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/unit/menu/menu_core.js
Expand Up @@ -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 );
3 changes: 2 additions & 1 deletion ui/jquery.ui.menu.js
Expand Up @@ -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 ] );

Expand Down

0 comments on commit 78c593b

Please sign in to comment.