Duidelijkere hovers, geen zichtbare pakkettenteller, nav schakelt op md met animatie en zonder CTA in mobiel menu

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 16:37:28 +01:00
co-authored by Claude Sonnet 5.5
parent f47528073d
commit 0d7be249f5
11 changed files with 116 additions and 81 deletions
+38 -35
View File
@@ -5,11 +5,13 @@ import { VariantToggle } from '../ui/VariantToggle';
import { handleAnchorClick } from '../../utils/scrollToHash';
/**
* Navigation of design B: part of the brand-red header (not sticky), white text, the CTA as a
* white block. The mobile menu (hamburger) is kept for small screens; years are not in the menu.
* Navigation of design B: part of the brand-red header, white text, the CTA as a white block
* (desktop only). Below the `md` breakpoint a hamburger opens an animated overlay menu with the
* section links; the "Start project" CTA is not repeated there (the hero has its own buttons).
*/
export function Nav() {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const sectionLinks = navLinks.filter((link) => !link.isCta);
// Escape closes the mobile menu (keyboard users).
useEffect(() => {
@@ -27,35 +29,35 @@ export function Nav() {
}
return (
<nav aria-label="Hoofdnavigatie" className="sticky top-0 z-40 bg-brand text-on-brand sm:static">
<div className="mx-auto flex min-h-[84px] max-w-[1280px] items-center justify-between gap-6 px-6 sm:px-8">
<nav aria-label="Hoofdnavigatie" className="sticky top-0 z-40 bg-brand text-on-brand md:static">
<div className="mx-auto flex min-h-[84px] max-w-[1280px] items-center justify-between gap-4 px-6 sm:px-8">
<a
href="#top"
onClick={(event) => handleAnchorClick(event, '#top')}
className="flex items-baseline gap-2 py-2.5 no-underline"
className="flex shrink-0 items-baseline gap-2 py-2.5 no-underline"
>
<span className="text-2xl font-black tracking-tight [font-stretch:125%]">SLP</span>
<span className="text-base font-normal">Software</span>
</a>
<ul className="flex items-center gap-3 sm:gap-8">
<ul className="flex items-center gap-3 md:gap-5 lg:gap-8">
{navLinks.map((link) =>
link.isCta ? (
<li key={link.href} className="hidden sm:block">
<li key={link.href} className="hidden md:block">
<a
href={link.href}
onClick={(event) => handleAnchorClick(event, link.href)}
className="inline-block bg-white px-[18px] py-[11px] text-[15px] font-bold text-brand no-underline hover:opacity-90"
className="inline-block whitespace-nowrap bg-white px-[18px] py-[11px] text-[15px] font-bold text-brand no-underline transition-colors hover:bg-inv hover:text-white"
data-testid="nav-cta-link"
>
{link.label}
</a>
</li>
) : (
<li key={link.href} className="hidden sm:block">
<li key={link.href} className="hidden md:block">
<a
href={link.href}
onClick={(event) => handleAnchorClick(event, link.href)}
className="inline-block py-3 text-[15px] font-medium no-underline hover:opacity-85"
className="inline-block whitespace-nowrap py-3 text-[15px] font-medium no-underline decoration-2 underline-offset-[10px] transition-colors hover:underline"
>
{link.label}
</a>
@@ -68,7 +70,7 @@ export function Nav() {
<li>
<VariantToggle tone="onBrand" />
</li>
<li className="sm:hidden">
<li className="md:hidden">
<button
type="button"
onClick={() => setIsMenuOpen((open) => !open)}
@@ -76,7 +78,7 @@ export function Nav() {
aria-expanded={isMenuOpen}
aria-controls="mobile-nav-menu"
data-testid="nav-mobile-toggle"
className="flex h-11 w-11 items-center justify-center rounded-full border border-white/70 text-on-brand transition-colors hover:border-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
className="flex h-11 w-11 items-center justify-center rounded-full border border-white/70 text-on-brand transition-colors hover:border-white hover:bg-white/15 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
<span className="sr-only">{isMenuOpen ? 'Sluit menu' : 'Open menu'}</span>
<svg
@@ -99,29 +101,30 @@ export function Nav() {
</li>
</ul>
</div>
{isMenuOpen ? (
<ul
id="mobile-nav-menu"
data-testid="nav-mobile-menu"
className="absolute inset-x-0 top-full z-40 flex flex-col gap-1 border-t border-white/30 bg-inv px-6 py-3 text-white shadow-[0_12px_24px_rgba(0,0,0,0.35)] sm:hidden"
>
{navLinks.map((link) => (
<li key={link.href}>
<a
href={link.href}
onClick={(event) => handleMobileLinkClick(event, link.href)}
className={
link.isCta
? 'mt-1 block bg-white px-4 py-3 text-[15px] font-bold text-brand no-underline'
: 'block px-1 py-3 text-[15px] font-medium no-underline hover:opacity-85'
}
>
{link.label}
</a>
</li>
))}
</ul>
) : null}
{/* Always mounted so it can animate; `invisible` removes it from the tab order and the
accessibility tree while closed. */}
<ul
id="mobile-nav-menu"
data-testid="nav-mobile-menu"
data-state={isMenuOpen ? 'open' : 'closed'}
className={`absolute inset-x-0 top-full z-40 flex flex-col gap-1 border-t border-white/30 bg-inv px-6 py-3 text-white shadow-[0_12px_24px_rgba(0,0,0,0.35)] transition-[opacity,transform,visibility] duration-200 ease-out motion-reduce:transition-none md:hidden ${
isMenuOpen
? 'visible translate-y-0 opacity-100'
: 'pointer-events-none invisible -translate-y-2 opacity-0'
}`}
>
{sectionLinks.map((link) => (
<li key={link.href}>
<a
href={link.href}
onClick={(event) => handleMobileLinkClick(event, link.href)}
className="block px-1 py-3 text-[15px] font-medium no-underline transition-colors hover:bg-white/10"
>
{link.label}
</a>
</li>
))}
</ul>
</nav>
);
}
+43 -13
View File
@@ -18,9 +18,10 @@ describe('Nav', () => {
it('renders all nav links including the CTA', () => {
renderNav();
expect(screen.getByText('Pakketten')).toBeInTheDocument();
expect(screen.getByText('Werkwijze')).toBeInTheDocument();
expect(screen.getByText('Over')).toBeInTheDocument();
// desktop bar + (hidden) mobile menu
expect(screen.getAllByText('Pakketten')).toHaveLength(2);
expect(screen.getAllByText('Werkwijze')).toHaveLength(2);
expect(screen.getAllByText('Over')).toHaveLength(2);
expect(screen.getByTestId('nav-cta-link')).toHaveTextContent('Start project');
});
@@ -47,20 +48,30 @@ describe('Nav', () => {
expect(toggle).toHaveAttribute('aria-pressed', 'true');
});
it('opens and closes the mobile menu via the toggle button', () => {
it('opens and closes the animated mobile menu via the toggle button', () => {
renderNav();
expect(screen.queryByTestId('nav-mobile-menu')).not.toBeInTheDocument();
const menu = screen.getByTestId('nav-mobile-menu');
expect(menu).toHaveAttribute('data-state', 'closed');
// Closed: hidden from the tab order and the accessibility tree.
expect(menu).toHaveClass('invisible', 'opacity-0');
const mobileToggle = screen.getByTestId('nav-mobile-toggle');
expect(mobileToggle).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(mobileToggle);
expect(mobileToggle).toHaveAttribute('aria-expanded', 'true');
const mobileMenu = screen.getByTestId('nav-mobile-menu');
expect(mobileMenu).toBeInTheDocument();
expect(menu).toHaveAttribute('data-state', 'open');
expect(menu).toHaveClass('visible', 'opacity-100');
fireEvent.click(mobileToggle);
expect(screen.queryByTestId('nav-mobile-menu')).not.toBeInTheDocument();
expect(menu).toHaveAttribute('data-state', 'closed');
});
it('animates opening and closing, but not under reduced motion', () => {
renderNav();
const menu = screen.getByTestId('nav-mobile-menu');
expect(menu).toHaveClass('transition-[opacity,transform,visibility]', 'duration-200');
expect(menu).toHaveClass('motion-reduce:transition-none');
});
it('shows the mobile menu as a dark overlay below the bar that does not push the page, and closes on Escape', () => {
@@ -69,15 +80,35 @@ describe('Nav', () => {
const menu = screen.getByTestId('nav-mobile-menu');
expect(menu).toHaveClass('absolute', 'top-full', 'bg-inv');
fireEvent.keyDown(document, { key: 'Escape' });
expect(screen.queryByTestId('nav-mobile-menu')).not.toBeInTheDocument();
expect(menu).toHaveAttribute('data-state', 'closed');
});
it('keeps the bar visible while scrolling on small screens only', () => {
it('does not repeat the "Start project" button in the mobile menu', () => {
renderNav();
const menu = screen.getByTestId('nav-mobile-menu');
const labels = Array.from(menu.querySelectorAll('a')).map((a) => a.textContent);
expect(labels).toEqual(['Over', 'Pakketten', 'Werkwijze']);
});
it('keeps the CTA on one line and switches to the desktop bar at the md breakpoint', () => {
renderNav();
const cta = screen.getByTestId('nav-cta-link');
expect(cta).toHaveClass('whitespace-nowrap');
expect(cta.closest('li')).toHaveClass('hidden', 'md:block');
expect(screen.getByTestId('nav-mobile-toggle').closest('li')).toHaveClass('md:hidden');
});
it('gives the CTA a clearly visible hover (inverts to black)', () => {
renderNav();
expect(screen.getByTestId('nav-cta-link')).toHaveClass('hover:bg-inv', 'hover:text-white');
});
it('keeps the bar visible while scrolling below the md breakpoint only', () => {
renderNav();
expect(screen.getByRole('navigation', { name: 'Hoofdnavigatie' })).toHaveClass(
'sticky',
'top-0',
'sm:static',
'md:static',
);
});
@@ -85,10 +116,9 @@ describe('Nav', () => {
renderNav();
fireEvent.click(screen.getByTestId('nav-mobile-toggle'));
const mobileMenu = screen.getByTestId('nav-mobile-menu');
expect(mobileMenu).toBeInTheDocument();
const link = mobileMenu.querySelector('a');
expect(link).not.toBeNull();
fireEvent.click(link as HTMLAnchorElement);
expect(screen.queryByTestId('nav-mobile-menu')).not.toBeInTheDocument();
expect(mobileMenu).toHaveAttribute('data-state', 'closed');
});
});