@@ -34,6 +34,14 @@ describe('details-menu element', function() {
3434 document . body . innerHTML = ''
3535 } )
3636
37+ it ( 'has default attributes set' , function ( ) {
38+ const details = document . querySelector ( 'details' )
39+ const summary = details . querySelector ( 'summary' )
40+ const menu = details . querySelector ( 'details-menu' )
41+ assert . equal ( summary . getAttribute ( 'role' ) , 'button' )
42+ assert . equal ( menu . getAttribute ( 'role' ) , 'menu' )
43+ } )
44+
3745 it ( 'opens and does not focus an item on mouse click' , function ( ) {
3846 const details = document . querySelector ( 'details' )
3947 const summary = details . querySelector ( 'summary' )
@@ -546,6 +554,55 @@ describe('details-menu element', function() {
546554 } )
547555 } )
548556
557+ describe ( 'with input[autofocus]' , function ( ) {
558+ beforeEach ( function ( ) {
559+ const container = document . createElement ( 'div' )
560+ container . innerHTML = `
561+ <details>
562+ <summary>Menu 1</summary>
563+ <details-menu role="none">
564+ <input autofocus>
565+ <div role="menu">
566+ <button role="menuitem">First item</button>
567+ </div>
568+ </details-menu>
569+ </details>
570+ `
571+ document . body . append ( container )
572+ } )
573+
574+ afterEach ( function ( ) {
575+ document . body . innerHTML = ''
576+ } )
577+
578+ it ( 'autofocuses on input on mouse click' , function ( ) {
579+ const details = document . querySelector ( 'details' )
580+ const summary = details . querySelector ( 'summary' )
581+ const menu = details . querySelector ( 'details-menu' )
582+ const input = details . querySelector ( 'input' )
583+
584+ summary . focus ( )
585+ details . open = true
586+ summary . dispatchEvent ( new MouseEvent ( 'mousedown' , { bubbles : true } ) )
587+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
588+ assert . equal ( menu . getAttribute ( 'role' ) , 'none' )
589+ assert . equal ( input , document . activeElement , 'mouse toggle open leaves summary focused' )
590+ } )
591+
592+ it ( 'autofocuses on input on keyboard activation' , function ( ) {
593+ const details = document . querySelector ( 'details' )
594+ const summary = details . querySelector ( 'summary' )
595+ const input = details . querySelector ( 'input' )
596+
597+ summary . focus ( )
598+ details . open = true
599+ summary . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' , bubbles : true } ) )
600+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
601+
602+ assert . equal ( input , document . activeElement , 'toggle open focuses on [autofocus]' )
603+ } )
604+ } )
605+
549606 describe ( 'closing the menu' , function ( ) {
550607 beforeEach ( function ( ) {
551608 const container = document . createElement ( 'div' )
0 commit comments