File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,33 @@ docReady(() => {
147
147
}
148
148
} ) ;
149
149
150
+ // Bind click handlers to dropdowns for keyboard users
151
+ docReady ( ( ) => {
152
+ let dropdownTriggers = document . querySelectorAll ( ".dropdown__trigger" ) ;
153
+ for ( let trigger of dropdownTriggers ) {
154
+ let button = trigger . querySelector ( "button" ) ;
155
+ let content = trigger . querySelector ( ".dropdown__content" ) ;
156
+
157
+ // If the user has clicked the button (either with a mouse or by pressing
158
+ // space/enter on the keyboard) show the content
159
+ button . addEventListener ( "click" , function ( ) {
160
+ // Toggle the visibility of the content
161
+ if ( content . classList . contains ( "display-block" ) ) {
162
+ content . classList . remove ( "display-block" ) ;
163
+ } else {
164
+ content . classList . add ( "display-block" ) ;
165
+ }
166
+ } ) ;
167
+
168
+ // If the user has moused onto the button and has happened to click it,
169
+ // remove the `display-block` class so that it doesn't stay visable when
170
+ // they mouse out
171
+ button . addEventListener ( "mouseout" , function ( ) {
172
+ content . classList . remove ( "display-block" ) ;
173
+ } ) ;
174
+ }
175
+ } ) ;
176
+
150
177
const application = Application . start ( ) ;
151
178
const context = require . context ( "./controllers" , true , / \. j s $ / ) ;
152
179
application . load ( definitionsFromContext ( context ) ) ;
Original file line number Diff line number Diff line change 156
156
display : none ;
157
157
}
158
158
159
+ .display-block {
160
+ display : block ;
161
+ }
162
+
159
163
// Mobile specific visibility
160
164
@media screen and (max-width : $mobile ) {
161
165
.hide-on-mobile {
You can’t perform that action at this time.
0 commit comments