File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 24
24
</ style >
25
25
</ head >
26
26
< body >
27
+ < h1 > Base examples</ h1 >
28
+
27
29
< details >
28
30
< summary > Best robot: < span data-menu-button > Unknown</ span > </ summary >
29
31
< details-menu >
60
62
</ details-menu >
61
63
</ details >
62
64
65
+ < h1 > Autofocus example</ h1 >
66
+ < p > < code > summary</ code > may have < code > autofocus</ code > so it's the initially focused element in the page.</ p >
67
+ < p > Then any focusable element inside the popup can declare autofocus too, so it gets focus when the popup is opened.</ p >
68
+
69
+ < details >
70
+ < summary data-menu-button autofocus > Autofocus picker</ summary >
71
+ < details-menu >
72
+ < input type ="text " autofocus />
73
+ < button type ="submit " name ="robot " value ="Hubot " role ="menuitemradio " data-menu-button-text > Hubot</ button >
74
+ < button type ="submit " name ="robot " value ="Bender " role ="menuitemradio " data-menu-button-text > Bender</ button >
75
+ < button type ="submit " name ="robot " value ="BB-8 " role ="menuitemradio " data-menu-button-text > BB-8</ button >
76
+ </ details-menu >
77
+ </ details >
78
+
63
79
< script type ="text/javascript ">
64
80
document . addEventListener ( 'details-menu-selected' , e => console . log ( e ) )
65
81
</ script >
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ function closeCurrentMenu(details: Element) {
132
132
133
133
function autofocus ( details : Element ) : boolean {
134
134
if ( ! details . hasAttribute ( 'open' ) ) return false
135
- const input = details . querySelector < HTMLElement > ( '[autofocus]' )
135
+ const input = details . querySelector < HTMLElement > ( 'details-menu [autofocus]' )
136
136
if ( input ) {
137
137
input . focus ( )
138
138
return true
Original file line number Diff line number Diff line change @@ -601,6 +601,22 @@ describe('details-menu element', function () {
601
601
602
602
assert . equal ( input , document . activeElement , 'toggle open focuses on [autofocus]' )
603
603
} )
604
+
605
+ it ( 'summary autofocus should not impact with inner autofocus element' , function ( ) {
606
+ const details = document . querySelector ( 'details' )
607
+ const summary = details . querySelector ( 'summary' )
608
+ const input = details . querySelector ( 'input' )
609
+
610
+ // Summary is the initial element of the entire page, while input is the initial element in the popup
611
+ summary . setAttribute ( 'autofocus' , '' )
612
+
613
+ summary . focus ( )
614
+ details . open = true
615
+ summary . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' , bubbles : true } ) )
616
+ details . dispatchEvent ( new CustomEvent ( 'toggle' ) )
617
+
618
+ assert . equal ( document . activeElement , input , 'toggle open focuses on [autofocus]' )
619
+ } )
604
620
} )
605
621
606
622
describe ( 'closing the menu' , function ( ) {
You can’t perform that action at this time.
0 commit comments