Skip to content

Commit bd0fe09

Browse files
committed
feat(mobile-nav): hide bar on scroll down, reveal on scroll up
1 parent 2f6ebb0 commit bd0fe09

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

app/components/Header/MobileBottomBar.client.vue

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ const contextLabel = computed(() => {
99
return ''
1010
})
1111
12+
// Hide on scroll down, reveal on scroll up (svelte.dev-style).
13+
// Keeps the bar visible while the menu is open, near the top of the page,
14+
// or when scroll direction flips.
15+
const hidden = shallowRef(false)
16+
const SCROLL_THRESHOLD = 24
17+
18+
if (typeof window !== 'undefined') {
19+
let lastY = window.scrollY
20+
const onScroll = () => {
21+
if (isOpen.value) {
22+
hidden.value = false
23+
lastY = window.scrollY
24+
return
25+
}
26+
const y = window.scrollY
27+
if (y < SCROLL_THRESHOLD) {
28+
hidden.value = false
29+
} else if (y > lastY) {
30+
hidden.value = true
31+
} else if (y < lastY) {
32+
hidden.value = false
33+
}
34+
lastY = y
35+
}
36+
useEventListener(window, 'scroll', onScroll, { passive: true })
37+
}
38+
39+
watch(isOpen, open => {
40+
if (open) hidden.value = false
41+
})
42+
1243
function handleSearchClick() {
1344
if (isOpen.value) close()
1445
nextTick(() => openCommandPalette())
@@ -22,7 +53,8 @@ function handleThemeClick() {
2253
<template>
2354
<Teleport to="body">
2455
<div
25-
class="sm:hidden fixed inset-x-0 bottom-0 z-50 bg-bg border-t border-border flex items-center gap-2 px-3 h-14"
56+
class="sm:hidden fixed inset-x-0 bottom-0 z-50 bg-bg border-t border-border flex items-center gap-2 px-3 h-14 transition-transform duration-200 ease-out motion-reduce:transition-none"
57+
:class="hidden ? 'translate-y-full' : 'translate-y-0'"
2658
:style="{ '--mobile-bar-height': '3.5rem' }"
2759
>
2860
<NuxtLink

0 commit comments

Comments
 (0)