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:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user