This document details the navigation bar component that provides site-wide navigation and smooth scrolling.
The Navbar component is a fixed-position navigation bar located in src/components/navbar/Navbar.tsx. It provides navigation links with smooth scrolling behavior and analytics tracking.
flowchart LR
accTitle: Navbar Navigation Structure
accDescr {
Navbar contains Home Button, Projects Link, Publications Link, and Socials Link. Home Button scrolls to Page
Top, Projects Link to Projects Grid, Publications Link to Publications, and Socials Link to Footer / Socials.
}
Navbar[Navbar] -->|Contains| Home[Home Button]
Navbar -->|Contains| Projects[Projects Link]
Navbar -->|Contains| Pubs[Publications Link]
Navbar -->|Contains| Socials[Socials Link]
Home -->|Scroll to| Top[Page Top]
Projects -->|Scroll to| ProjectsGrid[Projects Grid]
Pubs -->|Scroll to| PublicationsList[Publications]
Socials -->|Scroll to| Footer[Footer / Socials]
The navbar uses smooth scrolling to navigate to page sections:
onClick={(e) => {
logAnalyticsEvent('navbar_projects', {
name: 'navbar_projects',
type: 'click',
});
if (pathname === '/') {
e.preventDefault();
document.getElementById('projects-grid')?.scrollIntoView({ behavior: 'smooth' });
}
}};Each navigation action is logged using Firebase Analytics:
logAnalyticsEvent('navbar_home', {
name: 'navbar_home',
type: 'click',
});Tracked Events:
navbar_home- Home button clicknavbar_projects- Projects link clicknavbar_publications- Publications link clicknavbar_socials- Socials link click
Built with Material-UI AppBar and Toolbar components:
AppBar Styling:
backgroundColor: '#131518'- Dark background matching site themetransition: 'all 0.5s ease-in-out'- Smooth transitions for state changes
Toolbar Styling:
fontSize: '1.25rem'- Larger text for better readabilityheight: '2rem'- Compact height for minimal header footprintjustifyContent: 'space-between'- Distributes navigation items evenlytransition: 'all 0.5s ease-in-out'- Smooth transitionszIndex: 10- Ensures navbar stays above other content
Both components use the MUI sx prop for styling with these properties.
Uses Next.js usePathname hook to determine behavior:
const pathname = usePathname();
// On home page, prevent default and smooth scroll
// On other pages, navigate to home first
if (pathname === '/') {
e.preventDefault();
document.getElementById('content')?.scrollIntoView({ behavior: 'smooth' });
}Icon: HomeRoundedIcon from MUI
Target: Page top (#content)
Tooltip: "Home"
<Link aria-label='Home' href='/'>
<Tooltip arrow describeChild title='Home'>
<IconButton aria-label='Home button'>
<HomeRoundedIcon />
</IconButton>
</Tooltip>
</Link>Target: #projects-grid section
Text: "Projects"
Target: #publications section
Text: "Publications"
Icon: Profile picture (drawn avatar)
Target: #socials section (Footer)
Behavior: Displays a small profile image that links to the social media links in the footer
<Link aria-label='See socials' href='/#socials'>
<Image alt='Logo' height={24} src='/images/drawn/profile_pic_drawn.webp' width={24} />
</Link>sequenceDiagram
accTitle: Navbar Navigation Interaction Sequence
accDescr {
User clicks Projects, then Socials. For each click, Navbar logs an event to Analytics and checks pathname with
Router. On the home page, Navbar asks DOM for the matching section and DOM scrolls to it smoothly. On another
page, Navbar navigates Router to the matching home-page hash and Router scrolls DOM to that section.
}
participant User
participant Navbar
participant Router
participant Analytics
participant DOM
User->>Navbar: Click Projects
Navbar->>Analytics: Log event
Navbar->>Router: Check pathname
alt On Home Page
Navbar->>DOM: getElementById('projects-grid')
DOM->>DOM: scrollIntoView({behavior: 'smooth'})
else On Other Page
Navbar->>Router: Navigate to /#projects-grid
Router->>DOM: Scroll to section
end
User->>Navbar: Click Socials
Navbar->>Analytics: Log event
Navbar->>Router: Check pathname
alt On Home Page
Navbar->>DOM: getElementById('socials')
DOM->>DOM: scrollIntoView({behavior: 'smooth'})
else On Other Page
Navbar->>Router: Navigate to /#socials
Router->>DOM: Scroll to section
end
- ARIA Labels: All links have descriptive
aria-labelattributes - Tooltips: Visual feedback for icon buttons
- Keyboard Navigation: Fully keyboard accessible
- Focus Management: Proper focus indicators
- Semantic HTML: Uses proper
<Link>and<IconButton>components
Colors:
- Background:
#131518(dark gray) - Text: Inherited from theme
- Hover: MUI default hover state
Transitions:
- All transitions:
0.5s ease-in-out - Height:
2rem - z-index:
10(ensures navbar stays on top)
Test file: src/components/navbar/Navbar.test.tsx
Test Coverage:
- The navigation links render with their accessible names
- On the homepage, each link logs its analytics event and smooth-scrolls to its section
- Off the homepage, the Home link logs its analytics event without calling
scrollIntoView
import Navbar from '@components/navbar/Navbar';
// In layout or page
<Navbar />;GeneralLayout renders the Navbar as the first child of its root <div id='content'>, ahead of the <main> element and the footer. That root element is also the Home button's scroll target, so the button returns the reader to the top of the whole layout rather than to the top of the page content. See Layouts for the surrounding structure.
The component relies on the following element IDs:
content- Page containerprojects-grid- Projects sectionpublications- Publications sectionsocials- Socials section (Footer)
Ensure these IDs exist in your page structure.
- Client Component: Uses
'use client'for browser APIs - Lightweight: Minimal re-renders
- Fixed Position: Always visible during scroll
- Analytics Batching: Firebase handles event batching
💡 Tip: Use descriptive aria-label and id attributes for smooth scrolling to work correctly.