@@ -96,13 +96,13 @@ describe('details-menu element', function() {
96
96
const [ first , second , rest ] = details . querySelectorAll ( '[role="menuitem"]' )
97
97
assert ( rest )
98
98
99
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) )
99
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' , bubbles : true } ) )
100
100
assert . equal ( first , document . activeElement , 'arrow down focuses first item' )
101
101
102
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) )
102
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' , bubbles : true } ) )
103
103
assert . equal ( second , document . activeElement , 'arrow down focuses second item' )
104
104
105
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' } ) )
105
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' , bubbles : true } ) )
106
106
assert . equal ( first , document . activeElement , 'arrow up focuses first item' )
107
107
} )
108
108
@@ -116,11 +116,23 @@ describe('details-menu element', function() {
116
116
first . focus ( )
117
117
assert . equal ( first , document . activeElement )
118
118
119
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' } ) )
119
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' , bubbles : true } ) )
120
120
assert . equal ( summary , document . activeElement , 'escape focuses summary' )
121
121
assert ( ! details . open , 'details toggles closed' )
122
122
} )
123
123
124
+ it ( 'allow propagation on escape if details is closed' , function ( ) {
125
+ const details = document . querySelector ( 'details' )
126
+ const summary = details . querySelector ( 'summary' )
127
+
128
+ document . addEventListener ( 'keydown' , event => {
129
+ if ( event . key === 'Escape' ) summary . textContent = 'Propagated'
130
+ } )
131
+
132
+ summary . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' , bubbles : true } ) )
133
+ assert . equal ( summary . textContent , 'Propagated' )
134
+ } )
135
+
124
136
it ( 'updates the button label with text' , function ( ) {
125
137
const details = document . querySelector ( 'details' )
126
138
const summary = details . querySelector ( 'summary' )
@@ -197,7 +209,7 @@ describe('details-menu element', function() {
197
209
198
210
summary . focus ( )
199
211
summary . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true } ) )
200
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' } ) )
212
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' , bubbles : true } ) )
201
213
202
214
const notDisabled = details . querySelectorAll ( '[role="menuitem"]' ) [ 2 ]
203
215
assert . equal ( notDisabled , document . activeElement , 'arrow focuses on the last non-disabled item' )
@@ -217,7 +229,7 @@ describe('details-menu element', function() {
217
229
218
230
summary . focus ( )
219
231
summary . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true } ) )
220
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' } ) )
232
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' , bubbles : true } ) )
221
233
222
234
const disabled = details . querySelector ( '[disabled]' )
223
235
document . addEventListener ( 'details-menu-selected' , ( ) => eventCounter ++ , true )
@@ -365,7 +377,7 @@ describe('details-menu element', function() {
365
377
summary . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true } ) )
366
378
assert . equal ( summary , document . activeElement , 'summary remains focused on toggle' )
367
379
368
- details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) )
380
+ details . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' , bubbles : true } ) )
369
381
assert . equal ( summary , document . activeElement , 'summary remains focused on navigation' )
370
382
} )
371
383
} )
0 commit comments