@@ -546,6 +546,51 @@ describe('details-menu element', function() {
546
546
} )
547
547
} )
548
548
549
+ describe ( 'with input[autofocus]' , function ( ) {
550
+ beforeEach ( function ( ) {
551
+ const container = document . createElement ( 'div' )
552
+ container . innerHTML = `
553
+ <details>
554
+ <summary>Menu 1</summary>
555
+ <details-menu src="/test">
556
+ <input autofocus>
557
+ <button role="menuitem">First item</button>
558
+ </details-menu>
559
+ </details>
560
+ `
561
+ document . body . append ( container )
562
+ } )
563
+
564
+ afterEach ( function ( ) {
565
+ document . body . innerHTML = ''
566
+ } )
567
+
568
+ it ( 'autofocuses on input on mouse click' , function ( ) {
569
+ const details = document . querySelector ( 'details' )
570
+ const summary = details . querySelector ( 'summary' )
571
+ const input = details . querySelector ( 'input' )
572
+
573
+ summary . focus ( )
574
+ details . open = true
575
+ summary . dispatchEvent ( new MouseEvent ( 'mousedown' , { bubbles : true } ) )
576
+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
577
+ assert . equal ( input , document . activeElement , 'mouse toggle open leaves summary focused' )
578
+ } )
579
+
580
+ it ( 'autofocuses on input on keyboard activation' , function ( ) {
581
+ const details = document . querySelector ( 'details' )
582
+ const summary = details . querySelector ( 'summary' )
583
+ const input = details . querySelector ( 'input' )
584
+
585
+ summary . focus ( )
586
+ details . open = true
587
+ summary . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' , bubbles : true } ) )
588
+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
589
+
590
+ assert . equal ( input , document . activeElement , 'toggle open focuses on [autofocus]' )
591
+ } )
592
+ } )
593
+
549
594
describe ( 'closing the menu' , function ( ) {
550
595
beforeEach ( function ( ) {
551
596
const container = document . createElement ( 'div' )
0 commit comments