Skip to content

Commit 93f7ecc

Browse files
thollanderConduitry
authored andcommitted
Don't show/hide nav when clicking in docs sidebar
- Listens to hashchange event - Changes only the navbar visibilty when scroll not triggered by hashchange Resolves #2456
1 parent adcd13f commit 93f7ecc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

site/src/components/TopNav.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@
3535
};
3636
});
3737
38+
// Prevents navbar to show/hide when clicking in docs sidebar
39+
let hash_changed = false;
40+
function handle_hashchange() {
41+
hash_changed = true;
42+
}
43+
3844
let last_scroll = 0;
3945
function handle_scroll() {
4046
const scroll = window.pageYOffset;
41-
visible = (scroll < 50 || scroll < last_scroll);
47+
if (!hash_changed) {
48+
visible = (scroll < 50 || scroll < last_scroll);
49+
}
4250
4351
last_scroll = scroll;
52+
hash_changed = false;
4453
}
4554
</script>
4655

@@ -227,7 +236,7 @@
227236
}
228237
</style>
229238

230-
<svelte:window on:scroll={handle_scroll}/>
239+
<svelte:window on:hashchange={handle_hashchange} on:scroll={handle_scroll} />
231240

232241
<header class:visible="{visible || open}">
233242
<nav>

0 commit comments

Comments
 (0)