@@ -274,6 +274,54 @@ describe('details-dialog-element', function() {
274274 } )
275275 } )
276276 } )
277+
278+ describe ( 'shadow DOM context' , function ( ) {
279+ let shadowRoot , details , summary , dialog
280+ beforeEach ( function ( ) {
281+ const container = document . createElement ( 'div' )
282+ shadowRoot = container . attachShadow ( { mode : 'open' } )
283+ shadowRoot . innerHTML = `
284+ <details>
285+ <summary>Summary</summary>
286+ <details-dialog>
287+ <button id="button-1">Button 1</button>
288+ <button id="button-2">Button 2</button>
289+ <button ${ CLOSE_ATTR } >Button 3</button>
290+ </details-dialog>
291+ </details>`
292+ document . body . append ( container )
293+ details = shadowRoot . querySelector ( 'details' )
294+ summary = shadowRoot . querySelector ( 'summary' )
295+ dialog = shadowRoot . querySelector ( 'details-dialog' )
296+ } )
297+
298+ afterEach ( function ( ) {
299+ document . body . innerHTML = ''
300+ } )
301+
302+ it ( 'closes when escape key is pressed' , async function ( ) {
303+ assert ( ! details . open )
304+ dialog . toggle ( true )
305+ await waitForToggleEvent ( details )
306+ assert ( details . open )
307+ triggerKeydownEvent ( details , 'Escape' )
308+ assert ( ! details . open )
309+ } )
310+
311+ it ( 'manages focus' , async function ( ) {
312+ summary . click ( )
313+ await waitForToggleEvent ( details )
314+ assert . equal ( shadowRoot . activeElement , dialog )
315+ triggerKeydownEvent ( details , 'Tab' )
316+ assert . equal ( shadowRoot . activeElement , shadowRoot . querySelector ( `#button-1` ) )
317+ triggerKeydownEvent ( details , 'Tab' )
318+ assert . equal ( shadowRoot . activeElement , shadowRoot . querySelector ( `#button-2` ) )
319+ triggerKeydownEvent ( details , 'Tab' )
320+ assert . equal ( shadowRoot . activeElement , shadowRoot . querySelector ( `[${ CLOSE_ATTR } ]` ) )
321+ triggerKeydownEvent ( details , 'Tab' )
322+ assert . equal ( shadowRoot . activeElement , shadowRoot . querySelector ( `#button-1` ) )
323+ } )
324+ } )
277325} )
278326
279327function waitForToggleEvent ( details ) {
0 commit comments