Skip to content

Commit d8f51e3

Browse files
Hide the sidebar when collapsed to prevent browser search to find text from it
1 parent f3ee794 commit d8f51e3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/front-end/css/chrome.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ html:not(.sidebar-resizing) .sidebar {
530530
/* sidebar-hidden */
531531
#sidebar-toggle-anchor:not(:checked) ~ .sidebar {
532532
transform: translateX(calc(0px - var(--sidebar-width) - var(--sidebar-resize-indicator-width)));
533-
z-index: -1;
534533
}
535534
[dir=rtl] #sidebar-toggle-anchor:not(:checked) ~ .sidebar {
536535
transform: translateX(calc(var(--sidebar-width) + var(--sidebar-resize-indicator-width)));

src/front-end/js/book.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,25 @@ aria-label="Show hidden lines"></button>';
521521
const sidebarToggleButton = document.getElementById('sidebar-toggle');
522522
const sidebarToggleAnchor = document.getElementById('sidebar-toggle-anchor');
523523
const sidebarResizeHandle = document.getElementById('sidebar-resize-handle');
524+
const sidebarCheckbox = document.getElementById('sidebar-toggle-anchor');
524525
let firstContact = null;
525526

527+
/* Because we cannot change the `display` using only CSS after/before the transition, we
528+
need JS to do it. We change the display to prevent the browsers search to find text inside
529+
the collapsed sidebar. */
530+
sidebar.addEventListener('transitionend', () => {
531+
/* We only change the display to "none" if we're collapsing the sidebar. */
532+
if (!sidebarCheckbox.checked) {
533+
sidebar.style.display = 'none';
534+
}
535+
});
536+
sidebarToggleButton.addEventListener('click', () => {
537+
/* To allow the sidebar expansion animation, we first need to put back the display. */
538+
if (!sidebarCheckbox.checked) {
539+
sidebar.style.display = '';
540+
}
541+
});
542+
526543
function showSidebar() {
527544
body.classList.remove('sidebar-hidden');
528545
body.classList.add('sidebar-visible');

0 commit comments

Comments
 (0)