fix: hide the post navbar while scrolling#104
Conversation
WalkthroughThe Navbar component now implements scroll-based visibility behavior on post pages. When users scroll down, the navbar hides; when scrolling up or near the top of the page, it becomes visible. The implementation uses requestAnimationFrame for performance optimization and tracks scroll delta to determine visibility state. Changes
Sequence DiagramsequenceDiagram
participant User
participant Window
participant RAF as requestAnimationFrame
participant Navbar
participant IntersectionObserver
User->>Window: Scrolls page
activate Window
Window->>Navbar: scroll event fires
deactivate Window
activate Navbar
Navbar->>RAF: Schedule scroll handler
RAF->>Navbar: Execute handler (batched)
Navbar->>Navbar: Calculate scroll delta<br/>(currentScroll - lastScrollY)
alt Scrolling down beyond threshold
Navbar->>Navbar: isNavbarVisible = false
else Scrolling up
Navbar->>Navbar: isNavbarVisible = true
else Near top (within threshold)
Navbar->>Navbar: isNavbarVisible = true
end
Navbar->>Navbar: Update lastScrollY
deactivate Navbar
IntersectionObserver->>Navbar: Intersection event (at top)
activate Navbar
Navbar->>Navbar: Update isOnTop state
deactivate Navbar
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/layout/navigation/Navbar.vue`:
- Around line 114-117: The navbar is only visually translated off-screen so its
interactive elements remain focusable; update the root element in Navbar.vue
(the element using the class bindings with isPostsPage, isOnTop,
isNavbarVisible) to set accessibility attributes when hidden: bind aria-hidden
and either inert (if supported) or tabindex behavior based on the same condition
that produces '-translate-y-full' (i.e., when isPostsPage && !isOnTop &&
!isNavbarVisible). Concretely, add :aria-hidden="isPostsPage && !isOnTop &&
!isNavbarVisible" and :inert="isPostsPage && !isOnTop && !isNavbarVisible"
(fallback: set tabindex="-1" on the root or programmatically remove focusability
of child interactive elements) so controls aren’t reachable by keyboard/screen
readers when the navbar is translated out.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 69498652-7af4-4877-87db-69d449d947c1
📒 Files selected for processing (1)
components/layout/navigation/Navbar.vue
| '-translate-y-full': isPostsPage && !isOnTop && !isNavbarVisible, | ||
| 'translate-y-0': !isPostsPage || isOnTop || isNavbarVisible | ||
| }" | ||
| class="border-base-0/20 absolute inset-x-0 top-0 z-10 transition duration-200" | ||
| class="border-base-0/20 absolute inset-x-0 top-0 z-10 transform-gpu transition-[transform,background-color,box-shadow,backdrop-filter] duration-200 will-change-transform" |
There was a problem hiding this comment.
Hidden navbar remains focusable off-screen (a11y issue).
At Line 114, the navbar is only translated out of view. Menu controls can still receive focus while invisible, which is confusing for keyboard/screen-reader users.
♿ Suggested fix
<div
+ :aria-hidden="isPostsPage && !isOnTop && !isNavbarVisible"
+ :inert="isPostsPage && !isOnTop && !isNavbarVisible"
:class="{
'fixed!': isPostsPage,
'bg-base-1000/60 shadow-lg backdrop-blur-lg backdrop-saturate-200 md:border-b-2': isPostsPage && !isOnTop,
'-translate-y-full': isPostsPage && !isOnTop && !isNavbarVisible,
- 'translate-y-0': !isPostsPage || isOnTop || isNavbarVisible
+ 'translate-y-0': !isPostsPage || isOnTop || isNavbarVisible,
+ 'pointer-events-none': isPostsPage && !isOnTop && !isNavbarVisible
}"
class="border-base-0/20 absolute inset-x-0 top-0 z-10 transform-gpu transition-[transform,background-color,box-shadow,backdrop-filter] duration-200 will-change-transform"
>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@components/layout/navigation/Navbar.vue` around lines 114 - 117, The navbar
is only visually translated off-screen so its interactive elements remain
focusable; update the root element in Navbar.vue (the element using the class
bindings with isPostsPage, isOnTop, isNavbarVisible) to set accessibility
attributes when hidden: bind aria-hidden and either inert (if supported) or
tabindex behavior based on the same condition that produces '-translate-y-full'
(i.e., when isPostsPage && !isOnTop && !isNavbarVisible). Concretely, add
:aria-hidden="isPostsPage && !isOnTop && !isNavbarVisible" and
:inert="isPostsPage && !isOnTop && !isNavbarVisible" (fallback: set
tabindex="-1" on the root or programmatically remove focusability of child
interactive elements) so controls aren’t reachable by keyboard/screen readers
when the navbar is translated out.
Summary
Validation
Summary by CodeRabbit
New Features
Style