@@ -228,6 +228,32 @@ describe('MenuBar', () => {
228
228
}
229
229
) ;
230
230
231
+ it ( 'should toggle tabindex of menu bar items with left/right arrow keys' , ( ) => {
232
+ focusMenuBar ( ) ;
233
+
234
+ dispatchKeyboardEvent ( nativeMenuBar , 'keydown' , RIGHT_ARROW ) ;
235
+ detectChanges ( ) ;
236
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( - 1 ) ;
237
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toEqual ( 0 ) ;
238
+
239
+ dispatchKeyboardEvent ( nativeMenuBar , 'keydown' , RIGHT_ARROW ) ;
240
+ detectChanges ( ) ;
241
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( 0 ) ;
242
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toEqual ( - 1 ) ;
243
+
244
+ dispatchKeyboardEvent ( nativeMenuBar , 'keydown' , LEFT_ARROW ) ;
245
+ detectChanges ( ) ;
246
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( - 1 ) ;
247
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toEqual ( 0 ) ;
248
+
249
+ dispatchKeyboardEvent ( nativeMenuBar , 'keydown' , LEFT_ARROW ) ;
250
+ detectChanges ( ) ;
251
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( 0 ) ;
252
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toEqual ( - 1 ) ;
253
+
254
+ expect ( nativeMenus . length ) . toBe ( 0 ) ;
255
+ } ) ;
256
+
231
257
it (
232
258
"should open the focused menu item's menu and focus the first submenu" +
233
259
' item on the down key' ,
@@ -264,6 +290,28 @@ describe('MenuBar', () => {
264
290
265
291
expect ( document . activeElement ) . toEqual ( fileMenuNativeItems [ 0 ] ) ;
266
292
} ) ;
293
+
294
+ it (
295
+ 'should set the tabindex to 0 on the active item and reset the previous active items ' +
296
+ 'to -1 when navigating down to a submenu and within it using the arrow keys' ,
297
+ ( ) => {
298
+ focusMenuBar ( ) ;
299
+
300
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( 0 ) ;
301
+
302
+ dispatchKeyboardEvent ( menuBarNativeItems [ 0 ] , 'keydown' , SPACE ) ;
303
+ detectChanges ( ) ;
304
+
305
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toEqual ( - 1 ) ;
306
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toEqual ( 0 ) ;
307
+
308
+ dispatchKeyboardEvent ( fileMenuNativeItems [ 0 ] , 'keydown' , DOWN_ARROW ) ;
309
+ detectChanges ( ) ;
310
+
311
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toEqual ( - 1 ) ;
312
+ expect ( fileMenuNativeItems [ 1 ] . tabIndex ) . toEqual ( 0 ) ;
313
+ }
314
+ ) ;
267
315
} ) ;
268
316
269
317
describe ( 'for Menu' , ( ) => {
@@ -1041,6 +1089,60 @@ describe('MenuBar', () => {
1041
1089
expect ( nativeMenus . length ) . toBe ( 0 ) ;
1042
1090
}
1043
1091
) ;
1092
+
1093
+ it (
1094
+ 'should not set the tabindex when hovering over menubar item and there is no open' +
1095
+ ' sibling menu' ,
1096
+ ( ) => {
1097
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
1098
+ detectChanges ( ) ;
1099
+
1100
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1101
+ }
1102
+ ) ;
1103
+
1104
+ it (
1105
+ 'should set the tabindex of the opened trigger to 0 and toggle sibling tabindex' +
1106
+ ' on hover' ,
1107
+ ( ) => {
1108
+ openFileMenu ( ) ;
1109
+
1110
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1111
+
1112
+ dispatchMouseEvent ( menuBarNativeItems [ 1 ] , 'mouseenter' ) ;
1113
+ detectChanges ( ) ;
1114
+
1115
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1116
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toBe ( 0 ) ;
1117
+
1118
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
1119
+ detectChanges ( ) ;
1120
+
1121
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1122
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toBe ( - 1 ) ;
1123
+ }
1124
+ ) ;
1125
+
1126
+ it (
1127
+ 'should set the tabindex to 0 on the active item and reset the previous active items ' +
1128
+ 'to -1 when navigating down to a submenu and within it using a mouse' ,
1129
+ ( ) => {
1130
+ openFileMenu ( ) ;
1131
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1132
+
1133
+ dispatchMouseEvent ( fileMenuNativeItems [ 0 ] , 'mouseenter' ) ;
1134
+ detectChanges ( ) ;
1135
+
1136
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1137
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1138
+
1139
+ dispatchMouseEvent ( fileMenuNativeItems [ 1 ] , 'mouseenter' ) ;
1140
+ detectChanges ( ) ;
1141
+
1142
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1143
+ expect ( fileMenuNativeItems [ 1 ] . tabIndex ) . toBe ( 0 ) ;
1144
+ }
1145
+ ) ;
1044
1146
} ) ;
1045
1147
} ) ;
1046
1148
0 commit comments