Skip to content

Commit 0cbe66e

Browse files
author
Carlos Gutiérrez
authored
Fix book menu (#651)
* Fix onlick event for affecting all 'aria-expanded' buttons * Preserve a11y behaviour for download dropdown
1 parent ce35b0d commit 0cbe66e

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

assets/src/scripts/routes/common.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export default {
107107

108108
// Assign the button
109109
let btn = heading.querySelector( 'button' );
110+
let svg = heading.querySelector( 'button > .arrow' );
110111

111112
let links = content.querySelectorAll( 'a' );
112113

@@ -121,11 +122,14 @@ export default {
121122
};
122123
} );
123124

124-
document.onclick = e => {
125+
let $svgArrow = jQuery( 'button[aria-expanded] > svg' );
126+
let $toggleButton = jQuery( 'button[aria-expanded]' );
127+
128+
jQuery( $toggleButton, $svgArrow ).click( function ( e ) {
125129
// Cast the state as a boolean
126130
let expanded = btn.getAttribute( 'aria-expanded' ) === 'true' || false;
127131

128-
if ( btn === e.target ) {
132+
if ( btn === e.target || svg === e.target ) {
129133
// Switch the state
130134
btn.setAttribute( 'aria-expanded', ! expanded );
131135
// Switch the content's visibility
@@ -134,6 +138,23 @@ export default {
134138
btn.setAttribute( 'aria-expanded', false );
135139
content.hidden = true;
136140
}
141+
} );
142+
143+
document.onclick = e => {
144+
const downloadClass = 'book-header__cover__downloads';
145+
const $target = jQuery( e.target );
146+
const $downloadButton = jQuery( `.${downloadClass}` ).find( 'button' );
147+
148+
if ( $downloadButton.length === 0
149+
|| $target.closest( 'div' ).hasClass( downloadClass )
150+
|| $target.hasClass( 'dropdown-item' ) ) {
151+
return;
152+
}
153+
154+
if ( $downloadButton.attr( 'aria-expanded' ) === 'true' ) {
155+
btn.setAttribute( 'aria-expanded', false );
156+
content.hidden = true;
157+
}
137158
};
138159

139160
document.onkeydown = e => {

dist/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/scripts/book.js": "/scripts/book.js?id=b93e57644bb9aeafa54e",
2+
"/scripts/book.js": "/scripts/book.js?id=43b68b0ef999d4c586f4",
33
"/styles/book.css": "/styles/book.css?id=edcfbc383641276a5f72",
44
"/styles/web-house-style.css": "/styles/web-house-style.css?id=d3c1aedc7525b0f30ccd",
55
"/scripts/collapse-sections.js": "/scripts/collapse-sections.js?id=fed1957a6156e079cddf",

0 commit comments

Comments
 (0)