diff --git a/crates/mdbook-html/front-end/js/book.js b/crates/mdbook-html/front-end/js/book.js index fe74b7106f..9ced395bad 100644 --- a/crates/mdbook-html/front-end/js/book.js +++ b/crates/mdbook-html/front-end/js/book.js @@ -551,14 +551,16 @@ aria-label="Show hidden lines">'; } }); sidebarToggleButton.addEventListener('click', () => { + sidebarCheckbox.checked = !sidebarCheckbox.checked; /* To allow the sidebar expansion animation, we first need to put back the display. */ - if (!sidebarCheckbox.checked) { + if (sidebarCheckbox.checked) { sidebar.style.display = ''; // Workaround for Safari skipping the animation when changing // `display` and a transform in the same event loop. This forces a // reflow after updating the display. sidebar.offsetHeight; } + sidebarCheckbox.dispatchEvent(new Event('change', { bubbles: true })); }); function showSidebar() { diff --git a/crates/mdbook-html/front-end/templates/index.hbs b/crates/mdbook-html/front-end/templates/index.hbs index b1834189f9..a947d8c17b 100644 --- a/crates/mdbook-html/front-end/templates/index.hbs +++ b/crates/mdbook-html/front-end/templates/index.hbs @@ -143,9 +143,9 @@