@@ -43,6 +43,9 @@ $.widget( "ui.menubar", {
43
43
44
44
// Keep track of open submenus
45
45
this . openSubmenus = 0 ;
46
+
47
+ // Scorched earth: NOTHING can be tabbed to
48
+ this . menuItems . find ( "*" ) . slice ( 1 ) . attr ( "tabindex" , - 1 ) ;
46
49
} ,
47
50
48
51
_initializeMenubarsBoundElement : function ( ) {
@@ -65,6 +68,7 @@ $.widget( "ui.menubar", {
65
68
}
66
69
} ,
67
70
focusin : function ( ) {
71
+ this . _disableTabIndexOnFirstMenuItem ( ) ;
68
72
clearTimeout ( menubar . closeTimer ) ;
69
73
} ,
70
74
focusout : function ( event ) {
@@ -105,7 +109,7 @@ $.widget( "ui.menubar", {
105
109
isLastElement = ( index === ( collectionLength - 1 ) ) ;
106
110
107
111
if ( isFirstElement ) {
108
- $menuItem . data ( "prevMenuItem" , $ ( this . menuItems [ collectionLength - 1 ] ) ) ;
112
+ $menuItem . data ( "prevMenuItem" , $ ( this . menuItems [ collectionLength - 1 ] ) ) ;
109
113
$menuItem . data ( "nextMenuItem" , $ ( this . menuItems [ index + 1 ] ) ) ;
110
114
} else if ( isLastElement ) {
111
115
$menuItem . data ( "nextMenuItem" , $ ( this . menuItems [ 0 ] ) ) ;
@@ -171,6 +175,7 @@ $.widget( "ui.menubar", {
171
175
172
176
this . _on ( subMenus , {
173
177
keydown : function ( event ) {
178
+ $ ( event . target ) . attr ( "tabIndex" , 1 ) ;
174
179
var parentButton ,
175
180
menu = $ ( this ) ;
176
181
if ( menu . is ( ":hidden" ) ) {
@@ -192,6 +197,7 @@ $.widget( "ui.menubar", {
192
197
}
193
198
194
199
event . preventDefault ( ) ;
200
+ $ ( event . target ) . attr ( "tabIndex" , - 1 ) ;
195
201
break ;
196
202
case $ . ui . keyCode . RIGHT :
197
203
this . next ( event ) ;
@@ -206,15 +212,8 @@ $.widget( "ui.menubar", {
206
212
} ,
207
213
208
214
_initializeItem : function ( $anItem , menubar ) {
209
- //only the first item is eligible to receive the focus
210
215
var menuItemHasSubMenu = $anItem . data ( "parentMenuItem" ) . data ( "hasSubMenu" ) ;
211
216
212
- // Only the first item is tab-able
213
- if ( menubar . items . length === 1 ) {
214
- $anItem . attr ( "tabindex" , 1 ) ;
215
- } else {
216
- $anItem . attr ( "tabIndex" , - 1 ) ;
217
- }
218
217
219
218
this . _focusable ( this . items ) ;
220
219
this . _hoverable ( this . items ) ;
@@ -239,10 +238,12 @@ $.widget( "ui.menubar", {
239
238
240
239
__applyMouseAndKeyboardBehaviorForMenuItem : function ( $anItem , menubar ) {
241
240
menubar . _on ( $anItem , {
242
- focus : function ( ) {
241
+ focus : function ( ) {
242
+ $anItem . attr ( "tabIndex" , 1 ) ;
243
243
$anItem . addClass ( "ui-state-focus" ) ;
244
244
} ,
245
245
focusout : function ( ) {
246
+ $anItem . attr ( "tabIndex" , - 1 ) ;
246
247
$anItem . removeClass ( "ui-state-focus" ) ;
247
248
}
248
249
} ) ;
@@ -287,7 +288,6 @@ $.widget( "ui.menubar", {
287
288
this . _open ( event , menu ) ;
288
289
}
289
290
} ;
290
-
291
291
menubar . _on ( input , {
292
292
click : mouseBehaviorCallback ,
293
293
focus : mouseBehaviorCallback ,
@@ -312,6 +312,9 @@ $.widget( "ui.menubar", {
312
312
this . next ( event ) ;
313
313
event . preventDefault ( ) ;
314
314
break ;
315
+ case $ . ui . keyCode . TAB :
316
+ event . stopPropagation ( ) ;
317
+ break ;
315
318
}
316
319
} ;
317
320
@@ -439,7 +442,7 @@ $.widget( "ui.menubar", {
439
442
}
440
443
441
444
// set tabIndex -1 to have the button skipped on shift-tab when menu is open (it gets focus)
442
- button = menuItem . addClass ( "ui-state-active" ) . attr ( "tabIndex" , - 1 ) ;
445
+ button = menuItem . addClass ( "ui-state-active" ) ;
443
446
444
447
this . active = menu
445
448
. show ( )
@@ -501,7 +504,7 @@ $.widget( "ui.menubar", {
501
504
this . _submenuless_open ( event , nextMenuItem ) ;
502
505
}
503
506
} else {
504
- closestMenuItem . find ( ".ui-button" ) . attr ( "tabindex" , - 1 ) ;
507
+ closestMenuItem . find ( ".ui-button" ) ;
505
508
focusableTarget . focus ( ) ;
506
509
}
507
510
} ,
@@ -539,8 +542,12 @@ $.widget( "ui.menubar", {
539
542
menu . parent ( ".ui-menubar-item" ) . removeClass ( "ui-state-active" ) ;
540
543
} ,
541
544
545
+ _disableTabIndexOnFirstMenuItem : function ( ) {
546
+ this . items [ 0 ] . attr ( "tabIndex" , - 1 ) ;
547
+ } ,
548
+
542
549
_reenableTabIndexOnFirstMenuItem : function ( ) {
543
- $ ( this . menuItems [ 0 ] ) . find ( ".ui-widget" ) . attr ( "tabindex " , 1 ) ;
550
+ this . items [ 0 ] . attr ( "tabIndex " , 1 ) ;
544
551
}
545
552
546
553
} ) ;
0 commit comments