Skip to content

fix(navbar): sync active section highlight with scroll position#81

Merged
Amansingh0807 merged 1 commit into
Amansingh0807:masterfrom
vedamehar:fix/navbar-active-section-highlight
Mar 1, 2026
Merged

fix(navbar): sync active section highlight with scroll position#81
Amansingh0807 merged 1 commit into
Amansingh0807:masterfrom
vedamehar:fix/navbar-active-section-highlight

Conversation

@vedamehar

Copy link
Copy Markdown
Contributor

Description

Fixed the navbar active section highlighting issue where "Testimonial" was incorrectly shown as the active tab on page load instead of "Home". Implemented a scroll event listener that dynamically updates the navbar highlight as users navigate through different sections.

Changes Made:

  • Replace IntersectionObserver with scroll event listener
  • Ensure Home tab highlights by default on page load
  • Update navbar highlight dynamically as user scrolls through sections
  • Improve UX by matching visual indicator with actual page location

Related Issue

Resolves #80

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Performance improvement
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • UI/UX improvement
  • Code refactoring
  • Test update

Performance Improvements

  • Replaced IntersectionObserver: Eliminated unnecessary observer calculations with aggressive rootMargin
  • Simplified Detection Logic: Direct scroll position check is faster and more accurate
  • Reduced DOM Queries: Minimal re-renders and DOM access on scroll events
  • Better Memory Management: Scroll listener is more lightweight than maintaining multiple observer instances

Checklist

  • I have read the CONTRIBUTING.md guidelines
  • I have read the CODE_OF_CONDUCT.md
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have tested my changes thoroughly
  • Any dependent changes have been merged and published

AI Disclosure

  • Did you use AI tools to generate or assist with this code? (Yes)

AI Tool Used:

  • Which AI tool(s): GitHub Copilot / Claude AI
  • Which parts were AI-assisted:
    • Replaced IntersectionObserver logic with scroll event listener
    • Improved section detection algorithm
    • Performance optimization suggestions
    • Code structure and TypeScript types
  • Did you review and understand the AI-generated code: Yes - Thoroughly reviewed and tested the implementation

Testing

  • Tested locally
  • Tested in development mode
  • Linter passed (npm run lint)
  • No console errors or warnings
  • Responsive on mobile, tablet, desktop
  • Dark mode functionality maintained
  • No breaking changes to existing features

Test Configuration:

  • Node version: v18.0.0 or higher
  • Browser: Chrome/Firefox/Safari (Desktop & Mobile)
  • OS: Windows

Manual Testing Results:

  • ✅ Home tab highlights by default on page load
  • ✅ Navbar updates when scrolling to Features section
  • ✅ Navbar updates when scrolling to Testimonials section
  • ✅ Navbar updates when scrolling to FAQs section
  • ✅ Navbar updates when scrolling to Pricing section
  • ✅ Scroll back to top - Home highlights again
  • ✅ No console errors
  • ✅ Mobile responsive (hidden md:flex works correctly)
  • ✅ Dark/Light mode toggle works
  • ✅ Performance improvement verified - no lag on scroll

Screenshots

Before

The navbar showed "Testimonial" as highlighted by default on the home page instead of "Home".
image

After

The navbar now correctly shows "Home" as highlighted by default, and updates dynamically as the user scrolls through sections with improved performance.
image

Additional Notes

This fix improves both the user experience (visual indicator matches actual location) and performance (simpler scroll detection vs complex IntersectionObserver with aggressive margins). The implementation is more efficient and maintainable.


Note to Reviewers: All checklist items are completed. Performance improvements documented. AI assistance was used transparently. Code has been thoroughly tested locally.

- Replace IntersectionObserver with scroll event listener
- Ensure Home tab highlights by default on page load
- Update navbar highlight dynamically as user scrolls through sections
- Improve UX by matching visual indicator with actual page location
@vercel

vercel Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

@vedamehar is attempting to deploy a commit to the Aman Singh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added size/S UI/UX Improving the UI/UX labels Mar 1, 2026
@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown

✅ PR Checklist Complete

Great job @vedamehar! Your PR follows all the guidelines. A maintainer will review it soon. Thank you for your contribution! 🙏

@vercel

vercel Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
genform.ai Ready Ready Preview, Comment Mar 1, 2026 2:28pm

@Amansingh0807 Amansingh0807 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me, Thanks for Contributing.

@Amansingh0807 Amansingh0807 merged commit ec92f71 into Amansingh0807:master Mar 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S UI/UX Improving the UI/UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement]: Navbar Default state updation

2 participants