@@ -78,9 +78,7 @@ it('Moves the focus to the first menu item after pressing enter while focused on
78
78
79
79
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
80
80
81
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
82
- skipClick : true ,
83
- } ) ;
81
+ await user . keyboard ( '{Enter}' ) ;
84
82
85
83
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
86
84
} ) ;
@@ -92,9 +90,7 @@ it('Moves the focus to the first menu item after pressing space while focused on
92
90
93
91
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
94
92
95
- await user . type ( screen . getByText ( 'Primary' ) , '{ }' , {
96
- skipClick : true ,
97
- } ) ;
93
+ await user . keyboard ( '{ }' ) ;
98
94
99
95
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
100
96
} ) ;
@@ -140,9 +136,7 @@ it('Sets isOpen to true after pressing enter while focused on the menu button',
140
136
141
137
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
142
138
143
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
144
- skipClick : true ,
145
- } ) ;
139
+ await user . keyboard ( '{Enter}' ) ;
146
140
147
141
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'true' ) ;
148
142
} ) ;
@@ -152,9 +146,7 @@ it('Sets isOpen to false after pressing escape while focused on the menu button'
152
146
153
147
await user . click ( screen . getByText ( 'Primary' ) ) ;
154
148
155
- await user . type ( screen . getByText ( 'Primary' ) , '{Escape}' , {
156
- skipClick : true ,
157
- } ) ;
149
+ await user . keyboard ( '{Escape}' ) ;
158
150
159
151
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
160
152
} ) ;
@@ -168,9 +160,7 @@ it('Sets isOpen to true after pressing space while focused on the menu button',
168
160
169
161
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
170
162
171
- await user . type ( screen . getByText ( 'Primary' ) , '{ }' , {
172
- skipClick : true ,
173
- } ) ;
163
+ await user . keyboard ( '{ }' ) ;
174
164
175
165
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'true' ) ;
176
166
} ) ;
@@ -189,9 +179,7 @@ it('Moves the focus to the next element in the menu after pressing the down arro
189
179
190
180
await user . tab ( ) ;
191
181
192
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
193
- skipClick : true ,
194
- } ) ;
182
+ await user . keyboard ( '{Enter}' ) ;
195
183
196
184
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
197
185
@@ -212,9 +200,7 @@ it('Moves the focus to the previous element in the menu after pressing the up ar
212
200
213
201
await user . tab ( ) ;
214
202
215
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
216
- skipClick : true ,
217
- } ) ;
203
+ await user . keyboard ( '{Enter}' ) ;
218
204
219
205
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
220
206
@@ -246,9 +232,7 @@ it('Wraps the focus to the last element when pressing the up arrow at the beginn
246
232
247
233
await user . tab ( ) ;
248
234
249
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
250
- skipClick : true ,
251
- } ) ;
235
+ await user . keyboard ( '{Enter}' ) ;
252
236
253
237
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
254
238
@@ -269,9 +253,7 @@ it('Wraps the focus to the first element when pressing the down arrow at the end
269
253
270
254
await user . tab ( ) ;
271
255
272
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
273
- skipClick : true ,
274
- } ) ;
256
+ await user . keyboard ( '{Enter}' ) ;
275
257
276
258
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
277
259
@@ -303,13 +285,9 @@ it('Sets isOpen to false after pressing escape while focused on a menu item', as
303
285
304
286
await user . tab ( ) ;
305
287
306
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
307
- skipClick : true ,
308
- } ) ;
288
+ await user . keyboard ( '{Enter}' ) ;
309
289
310
- await user . type ( screen . getByText ( '1 Item' ) , '{Escape}' , {
311
- skipClick : true ,
312
- } ) ;
290
+ await user . keyboard ( '{Escape}' ) ;
313
291
314
292
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
315
293
} ) ;
@@ -319,9 +297,7 @@ it('Sets isOpen to false after pressing tab while focused on a menu item', async
319
297
320
298
await user . tab ( ) ;
321
299
322
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
323
- skipClick : true ,
324
- } ) ;
300
+ await user . keyboard ( '{Enter}' ) ;
325
301
326
302
await user . tab ( ) ;
327
303
@@ -333,13 +309,9 @@ it('Moves the focus to the menu button after pressing escape while focused on a
333
309
334
310
await user . tab ( ) ;
335
311
336
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
337
- skipClick : true ,
338
- } ) ;
312
+ await user . keyboard ( '{Enter}' ) ;
339
313
340
- await user . type ( screen . getByText ( '1 Item' ) , '{Escape}' , {
341
- skipClick : true ,
342
- } ) ;
314
+ await user . keyboard ( '{Escape}' ) ;
343
315
344
316
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
345
317
} ) ;
@@ -431,23 +403,17 @@ it('Ignores keys that buttons don’t need to handle', async () => {
431
403
432
404
await user . tab ( ) ;
433
405
434
- await user . type ( screen . getByText ( 'Primary' ) , 'Z' , {
435
- skipClick : true ,
436
- } ) ;
406
+ await user . keyboard ( 'Z' ) ;
437
407
} ) ;
438
408
439
409
it ( 'Ignores keys that items don’t need to handle' , async ( ) => {
440
410
const { user } = setup ( < TestComponent /> ) ;
441
411
442
412
await user . tab ( ) ;
443
413
444
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
445
- skipClick : true ,
446
- } ) ;
414
+ await user . keyboard ( '{Enter}' ) ;
447
415
448
- await user . type ( screen . getByText ( '1 Item' ) , 'Z' , {
449
- skipClick : true ,
450
- } ) ;
416
+ await user . keyboard ( 'Z' ) ;
451
417
452
418
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
453
419
} ) ;
@@ -457,27 +423,19 @@ it('Doesn’t crash when enter press occurs on a menu item', async () => {
457
423
458
424
await user . tab ( ) ;
459
425
460
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
461
- skipClick : true ,
462
- } ) ;
426
+ await user . keyboard ( '{Enter}' ) ;
463
427
464
- user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
465
- skipClick : true ,
466
- } ) ;
428
+ user . keyboard ( '{Enter}' ) ;
467
429
} ) ;
468
430
469
431
it ( 'Closes the menu after pressing enter on a menu item with a click handler' , async ( ) => {
470
432
const { user } = setup ( < TestComponent /> ) ;
471
433
472
434
await user . tab ( ) ;
473
435
474
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
475
- skipClick : true ,
476
- } ) ;
436
+ await user . keyboard ( '{Enter}' ) ;
477
437
478
- await user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
479
- skipClick : true ,
480
- } ) ;
438
+ await user . keyboard ( '{Enter}' ) ;
481
439
482
440
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
483
441
} ) ;
@@ -489,13 +447,9 @@ it('Activates the click handler of a menu item after pressing enter while focuse
489
447
490
448
await user . tab ( ) ;
491
449
492
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
493
- skipClick : true ,
494
- } ) ;
450
+ await user . keyboard ( '{Enter}' ) ;
495
451
496
- await user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
497
- skipClick : true ,
498
- } ) ;
452
+ await user . keyboard ( '{Enter}' ) ;
499
453
500
454
expect ( console . log ) . toHaveBeenCalledWith ( 'Item one clicked' ) ;
501
455
} ) ;
@@ -505,13 +459,9 @@ it('Closes the menu after pressing space on a menu item with a click handler', a
505
459
506
460
await user . tab ( ) ;
507
461
508
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
509
- skipClick : true ,
510
- } ) ;
462
+ await user . keyboard ( '{Enter}' ) ;
511
463
512
- await user . type ( screen . getByText ( '1 Item' ) , '{ }' , {
513
- skipClick : true ,
514
- } ) ;
464
+ await user . keyboard ( '{ }' ) ;
515
465
516
466
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
517
467
} ) ;
@@ -523,13 +473,9 @@ it('Activates the click handler of a menu item after pressing space while focuse
523
473
524
474
await user . tab ( ) ;
525
475
526
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
527
- skipClick : true ,
528
- } ) ;
476
+ await user . keyboard ( '{Enter}' ) ;
529
477
530
- await user . type ( screen . getByText ( '1 Item' ) , '{ }' , {
531
- skipClick : true ,
532
- } ) ;
478
+ await user . keyboard ( '{ }' ) ;
533
479
534
480
expect ( console . log ) . toHaveBeenCalledWith ( 'Item one clicked' ) ;
535
481
} ) ;
@@ -539,13 +485,9 @@ it('Moves the focus to the menu item with a label that starts with the correspon
539
485
540
486
await user . tab ( ) ;
541
487
542
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
543
- skipClick : true ,
544
- } ) ;
488
+ await user . keyboard ( '{Enter}' ) ;
545
489
546
- await user . type ( screen . getByText ( '1 Item' ) , '3' , {
547
- skipClick : true ,
548
- } ) ;
490
+ await user . keyboard ( '3' ) ;
549
491
550
492
expect ( screen . getByText ( '3 Item' ) ) . toHaveFocus ( ) ;
551
493
} ) ;
@@ -555,9 +497,7 @@ it('Moves the focus to the provided menu item when `moveFocus` is called', async
555
497
556
498
await user . tab ( ) ;
557
499
558
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
559
- skipClick : true ,
560
- } ) ;
500
+ await user . keyboard ( '{Enter}' ) ;
561
501
562
502
await user . click ( screen . getByTestId ( 'focus-third-item' ) ) ;
563
503
0 commit comments