@@ -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' , ( ) => {
@@ -884,6 +932,7 @@ describe('MenuBar', () => {
884
932
function openFileMenu ( ) {
885
933
dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
886
934
dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'click' ) ;
935
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
887
936
detectChanges ( ) ;
888
937
}
889
938
@@ -1052,6 +1101,61 @@ describe('MenuBar', () => {
1052
1101
expect ( nativeMenus . length ) . toBe ( 0 ) ;
1053
1102
}
1054
1103
) ;
1104
+
1105
+ it (
1106
+ 'should not set the tabindex when hovering over menubar item and there is no open' +
1107
+ ' sibling menu' ,
1108
+ ( ) => {
1109
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
1110
+ detectChanges ( ) ;
1111
+
1112
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1113
+ }
1114
+ ) ;
1115
+
1116
+ it (
1117
+ 'should set the tabindex of the opened trigger to 0 and toggle tabindex' +
1118
+ ' when hovering between items' ,
1119
+ ( ) => {
1120
+ openFileMenu ( ) ;
1121
+
1122
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1123
+
1124
+ dispatchMouseEvent ( menuBarNativeItems [ 1 ] , 'mouseenter' ) ;
1125
+ detectChanges ( ) ;
1126
+
1127
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1128
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toBe ( 0 ) ;
1129
+
1130
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseenter' ) ;
1131
+ detectChanges ( ) ;
1132
+
1133
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1134
+ expect ( menuBarNativeItems [ 1 ] . tabIndex ) . toBe ( - 1 ) ;
1135
+ }
1136
+ ) ;
1137
+
1138
+ it (
1139
+ 'should set the tabindex to 0 on the active item and reset the previous active items ' +
1140
+ 'to -1 when navigating down to a submenu and within it using a mouse' ,
1141
+ ( ) => {
1142
+ openFileMenu ( ) ;
1143
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1144
+
1145
+ dispatchMouseEvent ( fileMenuNativeItems [ 0 ] , 'mouseenter' ) ;
1146
+ dispatchMouseEvent ( menuBarNativeItems [ 0 ] , 'mouseout' ) ;
1147
+ detectChanges ( ) ;
1148
+
1149
+ expect ( menuBarNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1150
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toBe ( 0 ) ;
1151
+
1152
+ dispatchMouseEvent ( fileMenuNativeItems [ 1 ] , 'mouseenter' ) ;
1153
+ detectChanges ( ) ;
1154
+
1155
+ expect ( fileMenuNativeItems [ 0 ] . tabIndex ) . toBe ( - 1 ) ;
1156
+ expect ( fileMenuNativeItems [ 1 ] . tabIndex ) . toBe ( 0 ) ;
1157
+ }
1158
+ ) ;
1055
1159
} ) ;
1056
1160
} ) ;
1057
1161
0 commit comments