@@ -370,7 +370,6 @@ describe('MenuTrigger', function () {
370
370
act ( ( ) => { jest . runAllTimers ( ) ; } ) ; // FocusScope raf
371
371
}
372
372
373
- // Can't figure out why this isn't working for the v2 component
374
373
it . each `
375
374
Name | Component | props
376
375
${ 'MenuTrigger' } | ${ MenuTrigger } | ${ { onOpenChange} }
@@ -389,7 +388,39 @@ describe('MenuTrigger', function () {
389
388
expect ( document . activeElement ) . toBe ( button ) ;
390
389
} ) ;
391
390
392
- // Can't figure out why this isn't working for the v2 component
391
+ it . each `
392
+ Name | Component | props
393
+ ${ 'MenuTrigger' } | ${ MenuTrigger } | ${ { onOpenChange} }
394
+ ` ( '$Name does not clear selection with escape' , function ( { Component, props} ) {
395
+ let onSelectionChange = jest . fn ( ) ;
396
+ tree = renderComponent ( Component , props , { selectionMode : 'multiple' , defaultSelectedKeys : [ 'Foo' ] , onSelectionChange} ) ;
397
+ let button = tree . getByRole ( 'button' ) ;
398
+ triggerPress ( button ) ;
399
+ act ( ( ) => { jest . runAllTimers ( ) ; } ) ;
400
+ expect ( onSelectionChange ) . not . toHaveBeenCalled ( ) ;
401
+
402
+ let menu = tree . getByRole ( 'menu' ) ;
403
+ expect ( menu ) . toBeTruthy ( ) ;
404
+ expect ( within ( menu ) . getAllByRole ( 'menuitemcheckbox' ) [ 0 ] ) . toHaveAttribute ( 'aria-checked' , 'true' ) ;
405
+ fireEvent . keyDown ( menu , { key : 'Escape' , code : 27 , charCode : 27 } ) ;
406
+ act ( ( ) => { jest . runAllTimers ( ) ; } ) ; // FocusScope useLayoutEffect cleanup
407
+ act ( ( ) => { jest . runAllTimers ( ) ; } ) ; // FocusScope raf
408
+ expect ( menu ) . not . toBeInTheDocument ( ) ;
409
+ expect ( document . activeElement ) . toBe ( button ) ;
410
+ expect ( onSelectionChange ) . not . toHaveBeenCalled ( ) ;
411
+
412
+ // reopen and make sure we still have the selection
413
+ triggerPress ( button ) ;
414
+ act ( ( ) => { jest . runAllTimers ( ) ; } ) ;
415
+ expect ( onSelectionChange ) . not . toHaveBeenCalled ( ) ;
416
+
417
+ menu = tree . getByRole ( 'menu' ) ;
418
+ expect ( within ( menu ) . getAllByRole ( 'menuitemcheckbox' ) [ 0 ] ) . toHaveAttribute ( 'aria-checked' , 'true' ) ;
419
+ expect ( menu ) . toBeTruthy ( ) ;
420
+ fireEvent . keyDown ( menu , { key : 'Escape' , code : 27 , charCode : 27 } ) ;
421
+ expect ( onSelectionChange ) . not . toHaveBeenCalled ( ) ;
422
+ } ) ;
423
+
393
424
it . each `
394
425
Name | Component | props
395
426
${ 'MenuTrigger' } | ${ MenuTrigger } | ${ { onOpenChange} }
0 commit comments