Skip to content

Commit 4a2d393

Browse files
author
Steven G. Harms
committed
Menubar: move to next item applied focus() to too many items
`_move` was believed to specify just one item, called `focusableTarget`. Using the broader selectors this would return anything matching `a` or `button`. This means that the next item _as well as_ any `button`s or `a`s found thereunder would _also_ have their focus() event fired.
1 parent 4a24aa8 commit 4a2d393

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/unit/menubar/menubar_events.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ test( "hover over a menu item with no sub-menu should close open menu", function
4646
equal($(".ui-menu:visible").length, 0, "After triggering a sub-menu, a click on a peer menu item should close the opened sub-menu");
4747
});
4848

49+
test ( "_findNextFocusableTarget should find one and only one item", function() {
50+
expect(2);
51+
52+
var element = $("#bar1").menubar(),
53+
menubarWidget = element.data("ui-menubar"),
54+
firstMenuItem = $("#bar1 .ui-menubar-item").eq(0),
55+
expectedFocusableTarget = $("#bar1 .ui-menubar-item .ui-widget").eq(0),
56+
result = menubarWidget._findNextFocusableTarget( firstMenuItem );
57+
58+
equal( expectedFocusableTarget[0], result[0], "_findNextFocusableTarget should return the focusable element underneath the menuItem" );
59+
equal( 1, result.length, "One and only one item should be returned." );
60+
});
61+
4962
})( jQuery );

ui/jquery.ui.menubar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,17 @@ $.widget( "ui.menubar", {
476476
this._move( "prev", "last", event );
477477
},
478478

479+
_findNextFocusableTarget: function( menuItem ) {
480+
return menuItem.find(".ui-button");
481+
},
482+
479483
_move: function( direction, filter, event ) {
480484
var next,
481485
wrapItem;
482486

483487
var closestMenuItem = $( event.target ).closest(".ui-menubar-item"),
484488
nextMenuItem = closestMenuItem.data( direction + "MenuItem" ),
485-
focusableTarget = nextMenuItem.find("a, button");
489+
focusableTarget = this._findNextFocusableTarget( nextMenuItem );
486490

487491
if ( this.open ) {
488492
if ( nextMenuItem.data("hasSubMenu") ) {

0 commit comments

Comments
 (0)