Skip to content

Commit 0f33062

Browse files
author
Steven G. Harms
committed
Adds unit test: correct sub-menu-less menu item event behavior
Ensure open sub-menus close on sub-menu-less `click` or `mouseenter` events. See 9f53e0.
1 parent b9d0771 commit 0f33062

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

tests/unit/menubar/menubar_events.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ test( "handle click on menu item", function() {
2727
equal( logOutput(), "click,(1,2),afterclick,(2,1),(3,3),(1,2)", "Click order not valid." );
2828
});
2929

30+
test( "hover over a menu item with no sub-menu should close open menu", function() {
31+
expect( 2 );
32+
33+
var element = $( "#bar1" ).menubar();
34+
var links = $("#bar1 > li a");
35+
36+
var menuItemWithDropdown = links.eq(1);
37+
var menuItemWithoutDropdown = links.eq(0);
38+
39+
menuItemWithDropdown.trigger('click', {});
40+
menuItemWithoutDropdown.trigger('mouseenter', {});
41+
42+
equal( $(".ui-menu:visible").length, 0 );
43+
44+
menuItemWithDropdown.trigger('click', {});
45+
menuItemWithoutDropdown.trigger('click', {});
46+
47+
equal( $(".ui-menu:visible").length, 0 );
48+
49+
});
50+
3051
})( jQuery );

ui/jquery.ui.menubar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ $.widget( "ui.menubar", {
138138
}
139139
} else {
140140
// TODO use _on
141-
input.bind( "click.menubar mouseenter.menubar", function( event ) {
142-
if ( ( that.open && event.type === "mouseenter" ) || event.type === "click" ) {
143-
that._close();
144-
}
145-
});
141+
input.bind( "click mouseenter", function( event ) {
142+
if ( ( that.open && event.type === "mouseenter" ) || event.type === "click" ) {
143+
that._close();
144+
}
145+
});
146146
}
147147

148148
input

0 commit comments

Comments
 (0)