Skip to content

Commit fa6aa2c

Browse files
committed
Default the sidebar to visible in large screens
The code here leads me to believe that the intention is for the sidebar to be default visible on large screens (where `clientWidth` > 1080) and hidden otherwise. However, as previously written, if the `localStorage.getItem` call fails (for example, if the user agent is not accepting cookies), then we fall back to `sidebar = sidebar || 'visible';` — but `sidebar` is already set to `hidden`, so the `|| 'visible'` never happens. This results in the sidebar hiding itself on every navigation through an mdBook, meaning if you're just switching between sections trying to find something that you keep needing to re-open the sidebar.
1 parent 3966498 commit fa6aa2c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/theme/index.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@
9292
<!-- Hide / unhide sidebar before it is displayed -->
9393
<script>
9494
var html = document.querySelector('html');
95-
var sidebar = 'hidden';
95+
var sidebar = null;
9696
if (document.body.clientWidth >= 1080) {
9797
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
9898
sidebar = sidebar || 'visible';
99+
} else {
100+
sidebar = 'hidden';
99101
}
100102
html.classList.remove('sidebar-visible');
101103
html.classList.add("sidebar-" + sidebar);

0 commit comments

Comments
 (0)