@@ -519,10 +519,30 @@ aria-label="Show hidden lines"></button>';
519
519
const sidebar = document . getElementById ( 'sidebar' ) ;
520
520
const sidebarLinks = document . querySelectorAll ( '#sidebar a' ) ;
521
521
const sidebarToggleButton = document . getElementById ( 'sidebar-toggle' ) ;
522
- const sidebarToggleAnchor = document . getElementById ( 'sidebar-toggle-anchor' ) ;
523
522
const sidebarResizeHandle = document . getElementById ( 'sidebar-resize-handle' ) ;
523
+ const sidebarCheckbox = document . getElementById ( 'sidebar-toggle-anchor' ) ;
524
524
let firstContact = null ;
525
525
526
+
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
+ if ( ! document . documentElement . classList . contains ( 'sidebar-visible' ) ) {
531
+ sidebar . style . display = 'none' ;
532
+ }
533
+ sidebar . addEventListener ( 'transitionend' , ( ) => {
534
+ /* We only change the display to "none" if we're collapsing the sidebar. */
535
+ if ( ! sidebarCheckbox . checked ) {
536
+ sidebar . style . display = 'none' ;
537
+ }
538
+ } ) ;
539
+ sidebarToggleButton . addEventListener ( 'click' , ( ) => {
540
+ /* To allow the sidebar expansion animation, we first need to put back the display. */
541
+ if ( ! sidebarCheckbox . checked ) {
542
+ sidebar . style . display = '' ;
543
+ }
544
+ } ) ;
545
+
526
546
function showSidebar ( ) {
527
547
body . classList . add ( 'sidebar-visible' ) ;
528
548
Array . from ( sidebarLinks ) . forEach ( function ( link ) {
@@ -552,8 +572,8 @@ aria-label="Show hidden lines"></button>';
552
572
}
553
573
554
574
// Toggle sidebar
555
- sidebarToggleAnchor . addEventListener ( 'change' , function sidebarToggle ( ) {
556
- if ( sidebarToggleAnchor . checked ) {
575
+ sidebarCheckbox . addEventListener ( 'change' , function sidebarToggle ( ) {
576
+ if ( sidebarCheckbox . checked ) {
557
577
const current_width = parseInt (
558
578
document . documentElement . style . getPropertyValue ( '--sidebar-target-width' ) , 10 ) ;
559
579
if ( current_width < 150 ) {
@@ -577,7 +597,7 @@ aria-label="Show hidden lines"></button>';
577
597
if ( pos < 20 ) {
578
598
hideSidebar ( ) ;
579
599
} else {
580
- if ( body . classList . contains ( 'sidebar-hidden ' ) ) {
600
+ if ( ! body . classList . contains ( 'sidebar-visible ' ) ) {
581
601
showSidebar ( ) ;
582
602
}
583
603
pos = Math . min ( pos , window . innerWidth - 100 ) ;
0 commit comments