@@ -521,8 +521,29 @@ aria-label="Show hidden lines"></button>';
521
521
const sidebarToggleButton = document . getElementById ( 'sidebar-toggle' ) ;
522
522
const sidebarToggleAnchor = document . getElementById ( 'sidebar-toggle-anchor' ) ;
523
523
const sidebarResizeHandle = document . getElementById ( 'sidebar-resize-handle' ) ;
524
+ const sidebarCheckbox = document . getElementById ( 'sidebar-toggle-anchor' ) ;
524
525
let firstContact = null ;
525
526
527
+
528
+ /* Because we cannot change the `display` using only CSS after/before the transition, we
529
+ need JS to do it. We change the display to prevent the browsers search to find text inside
530
+ the collapsed sidebar. */
531
+ if ( ! document . documentElement . classList . contains ( 'sidebar-visible' ) ) {
532
+ sidebar . style . display = 'none' ;
533
+ }
534
+ sidebar . addEventListener ( 'transitionend' , ( ) => {
535
+ /* We only change the display to "none" if we're collapsing the sidebar. */
536
+ if ( ! sidebarCheckbox . checked ) {
537
+ sidebar . style . display = 'none' ;
538
+ }
539
+ } ) ;
540
+ sidebarToggleButton . addEventListener ( 'click' , ( ) => {
541
+ /* To allow the sidebar expansion animation, we first need to put back the display. */
542
+ if ( ! sidebarCheckbox . checked ) {
543
+ sidebar . style . display = '' ;
544
+ }
545
+ } ) ;
546
+
526
547
function showSidebar ( ) {
527
548
body . classList . add ( 'sidebar-visible' ) ;
528
549
Array . from ( sidebarLinks ) . forEach ( function ( link ) {
@@ -538,6 +559,7 @@ aria-label="Show hidden lines"></button>';
538
559
}
539
560
540
561
function hideSidebar ( ) {
562
+ console . trace ( ) ;
541
563
body . classList . remove ( 'sidebar-visible' ) ;
542
564
Array . from ( sidebarLinks ) . forEach ( function ( link ) {
543
565
link . setAttribute ( 'tabIndex' , - 1 ) ;
@@ -577,7 +599,7 @@ aria-label="Show hidden lines"></button>';
577
599
if ( pos < 20 ) {
578
600
hideSidebar ( ) ;
579
601
} else {
580
- if ( body . classList . contains ( 'sidebar-hidden ' ) ) {
602
+ if ( ! body . classList . contains ( 'sidebar-visible ' ) ) {
581
603
showSidebar ( ) ;
582
604
}
583
605
pos = Math . min ( pos , window . innerWidth - 100 ) ;
0 commit comments