Skip to content

Commit 484e382

Browse files
committed
Menu: Only set the mouseHandled flag if the event is going to bubble. Fixes #9469: on( "menuselect" )
not firing every time.
1 parent a377088 commit 484e382

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tests/unit/menu/menu_events.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,19 @@ test( "ensure default is prevented when clicking on anchors in disabled menus ",
619619
equal( logOutput(), "click,1,afterclick,disable,enable,3", "Click order not valid." );
620620
});
621621

622+
test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function() {
623+
expect( 1 );
624+
var element = $( "#menu1" ).menu({
625+
select: function( event, ui ) {
626+
log();
627+
event.stopPropagation();
628+
}
629+
});
630+
631+
click( element, "1" );
632+
click( element, "2" );
633+
634+
equal( logOutput(), "1,2", "Both select events were not triggered." );
635+
});
636+
622637
})( jQuery );

ui/jquery.ui.menu.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ $.widget( "ui.menu", {
7575
"click .ui-menu-item:has(a)": function( event ) {
7676
var target = $( event.target ).closest( ".ui-menu-item" );
7777
if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
78-
this.mouseHandled = true;
79-
8078
this.select( event );
79+
80+
// Only set the mouseHandled flag if the event will bubble, see #9469.
81+
if ( !event.isPropagationStopped() ) {
82+
this.mouseHandled = true;
83+
}
84+
8185
// Open submenu on click
8286
if ( target.has( ".ui-menu" ).length ) {
8387
this.expand( event );

0 commit comments

Comments
 (0)