Skip to content

Commit 485e0a0

Browse files
committed
Menu: Only focus menu after click if focus is on an element within menu. Fixes #9044 - Menu: Autofocus issue with dialog opened from menu widget
1 parent d13df39 commit 485e0a0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/unit/menu/menu_core.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,22 @@ test( "accessibility", function () {
2727
// Item roles are tested in the role option tests
2828
});
2929

30+
asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", function() {
31+
expect( 1 );
32+
var element = $( "#menu1" ).menu();
33+
34+
$( "<input>", { id: "test9044" } ).appendTo( "body" );
35+
36+
$( "#testID1" ).bind( "click", function() {
37+
$( "#test9044" ).focus();
38+
});
39+
40+
TestHelpers.menu.click( element, "3" );
41+
setTimeout( function() {
42+
equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" );
43+
$( "#test9044" ).remove();
44+
start();
45+
});
46+
});
47+
3048
})( jQuery );

ui/jquery.ui.menu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ $.widget( "ui.menu", {
8585
// Open submenu on click
8686
if ( target.has( ".ui-menu" ).length ) {
8787
this.expand( event );
88-
} else if ( !this.element.is( ":focus" ) ) {
88+
} else if ( !this.element.is( ":focus" ) && $( this.document[ 0 ].activeElement ).closest( ".ui-menu" ).length ) {
89+
8990
// Redirect focus to the menu
9091
this.element.trigger( "focus", [ true ] );
9192

0 commit comments

Comments
 (0)