Skip to content

Commit 74a3f2c

Browse files
committed
Menu: Move mousedown handler into _bind and fix focusing of the Menu after click. Fixes focus issues with Selectmenu and Autocomplete.
1 parent 2b9b2f2 commit 74a3f2c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ui/jquery.ui.menu.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ $.widget( "ui.menu", {
4040
id: this.menuId,
4141
role: "menu"
4242
})
43-
// Prevent focus from sticking to links inside menu after clicking
44-
// them (focus should always stay on UL during navigation).
45-
// If the link is clicked, redirect focus to the menu.
46-
// TODO move to _bind below
47-
.bind( "mousedown.menu", function( event ) {
48-
if ( $( event.target).is( "a" ) ) {
49-
event.preventDefault();
50-
$( this ).focus( 1 );
51-
}
52-
})
5343
// need to catch all clicks on disabled menu
5444
// not possible through _bind
5545
.bind( "click.menu", $.proxy( function( event ) {
@@ -58,6 +48,11 @@ $.widget( "ui.menu", {
5848
}
5949
}, this));
6050
this._bind({
51+
// Prevent focus from sticking to links inside menu after clicking
52+
// them (focus should always stay on UL during navigation).
53+
"mousedown .ui-menu-item > a": function( event ) {
54+
event.preventDefault();
55+
},
6156
"click .ui-menu-item:has(a)": function( event ) {
6257
event.stopImmediatePropagation();
6358
var target = $( event.currentTarget );
@@ -66,6 +61,8 @@ $.widget( "ui.menu", {
6661
this.focus( event, target );
6762
}
6863
this.select( event );
64+
// Redirect focus to the menu.
65+
this.element.focus();
6966
},
7067
"mouseover .ui-menu-item": function( event ) {
7168
event.stopImmediatePropagation();

0 commit comments

Comments
 (0)