Mobiel menu als donker overlay zonder de pagina te verschuiven, sticky balk onder sm, skiplink, focusring en h1 met screenreader-tekst

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 15:22:26 +01:00
co-authored by Claude Sonnet 5.5
parent aa843a5675
commit 1756ab1eb0
11 changed files with 114 additions and 8 deletions
+13 -3
View File
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { navLinks } from '../../features/landing/data/content';
import { ModeToggle } from '../ui/ModeToggle';
import { VariantToggle } from '../ui/VariantToggle';
@@ -11,13 +11,23 @@ import { handleAnchorClick } from '../../utils/scrollToHash';
export function Nav() {
const [isMenuOpen, setIsMenuOpen] = useState(false);
// Escape closes the mobile menu (keyboard users).
useEffect(() => {
if (!isMenuOpen) return;
const onKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') setIsMenuOpen(false);
};
document.addEventListener('keydown', onKey);
return () => document.removeEventListener('keydown', onKey);
}, [isMenuOpen]);
function handleMobileLinkClick(event: React.MouseEvent<HTMLAnchorElement>, href: string) {
handleAnchorClick(event, href);
setIsMenuOpen(false);
}
return (
<nav aria-label="Hoofdnavigatie" className="bg-brand text-on-brand">
<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">
<a
href="#top"
@@ -93,7 +103,7 @@ export function Nav() {
<ul
id="mobile-nav-menu"
data-testid="nav-mobile-menu"
className="flex flex-col gap-1 border-t border-white/30 px-6 py-3 sm:hidden"
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}>
+2
View File
@@ -1,6 +1,7 @@
import type { ReactNode } from 'react';
import { Nav } from './Nav';
import { Footer } from './Footer';
import { SkipLink } from './SkipLink';
import { VariantRenderer } from './VariantRenderer';
import { TransitionOverlay } from './TransitionOverlay';
import { LiveRegion } from './LiveRegion';
@@ -17,6 +18,7 @@ export function RootLayout({ children }: { children: ReactNode }) {
<VariantRenderer
b={
<>
<SkipLink />
<header>
<Nav />
</header>
+22
View File
@@ -0,0 +1,22 @@
/**
* "Naar de inhoud" link for keyboard and screen-reader users (WCAG 2.4.1). Hidden until focused.
* Handled in script because the app uses hash routing (a plain #main anchor would be taken by the
* router, see utils/scrollToHash).
*/
export function SkipLink() {
return (
<a
href="#main"
onClick={(event) => {
event.preventDefault();
const main = document.getElementById('main');
main?.focus();
main?.scrollIntoView({ block: 'start' });
}}
className="sr-only z-50 bg-white px-4 py-3 text-base font-bold text-[#0e0d0d] focus:not-sr-only focus:fixed focus:left-4 focus:top-4"
data-testid="skip-link"
>
Naar de inhoud
</a>
);
}
@@ -63,6 +63,24 @@ describe('Nav', () => {
expect(screen.queryByTestId('nav-mobile-menu')).not.toBeInTheDocument();
});
it('shows the mobile menu as a dark overlay below the bar that does not push the page, and closes on Escape', () => {
renderNav();
fireEvent.click(screen.getByTestId('nav-mobile-toggle'));
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();
});
it('keeps the bar visible while scrolling on small screens only', () => {
renderNav();
expect(screen.getByRole('navigation', { name: 'Hoofdnavigatie' })).toHaveClass(
'sticky',
'top-0',
'sm:static',
);
});
it('closes the mobile menu when a link inside it is clicked', () => {
renderNav();
fireEvent.click(screen.getByTestId('nav-mobile-toggle'));
@@ -1,5 +1,5 @@
import { render, screen, within } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { fireEvent, render, screen, within } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { RootLayout } from '../RootLayout';
import { ThemeProvider } from '../../../theme/ThemeProvider';
@@ -40,6 +40,15 @@ describe('RootLayout landmarks (NFR-1)', () => {
expect(screen.getByTestId('variant-toggle-button')).toHaveClass('text-on-brand');
});
it('offers a skip link that moves focus to the main region', () => {
Element.prototype.scrollIntoView = vi.fn();
renderLayout();
const skip = screen.getByTestId('skip-link');
expect(skip).toHaveAttribute('href', '#main');
fireEvent.click(skip);
expect(document.activeElement).toBe(screen.getByRole('main'));
});
it('has a live region for variant announcements', () => {
renderLayout();
expect(screen.getByRole('status')).toBeInTheDocument();
@@ -24,6 +24,8 @@ export function AboutSection() {
alt="Bryan Slop, oprichter van SLP Software"
width={480}
height={640}
loading="lazy"
decoding="async"
className="relative block aspect-[3/4] w-full object-cover object-[50%_30%]"
/>
</picture>
@@ -12,8 +12,8 @@ export function ContactSection() {
<h2
id="contact-heading"
className="text-[clamp(56px,10.5vw,168px)] font-extrabold leading-[0.88] tracking-[-0.03em] [font-stretch:125%]"
aria-label={contactInfo.heading}
>
<span className="sr-only">{contactInfo.heading}</span>
{contactInfo.displayHeading.map((line) => (
<span key={line} className="block" aria-hidden="true">
{line}
+1 -1
View File
@@ -12,8 +12,8 @@ export function Hero() {
<h1
id="hero-heading"
className="text-[clamp(56px,10.5vw,168px)] font-extrabold leading-[0.88] tracking-[-0.03em] [font-stretch:125%]"
aria-label={heroContent.heading}
>
<span className="sr-only">{heroContent.heading}</span>
{heroContent.displayHeading.map((line, index) => (
<span
key={line}
+7
View File
@@ -113,6 +113,13 @@ html {
}
}
/* Clear keyboard focus on every interactive element (WCAG 2.4.7); uses the text colour of the
surrounding block so it is visible on the brand-red header and on light/dark panels. */
:where(a, button, select, input, textarea, [tabindex]):focus-visible {
outline: 2px solid currentColor;
outline-offset: 3px;
}
body {
background-color: var(--color-bg);
color: var(--color-text);