Adds the shoot page layout and the shoot-type submenu

Shoot pages follow design E: breadcrumb, story blocks, process
timeline with icons, photo mosaic, FAQ, package block and booking
call to action, with per-shoot OG images. The navigation gets a
"Soorten fotoshoots" submenu (desktop panel, mobile group) built from
shootTypes, with exact current-page matching in menu, footer and
breadcrumb. A 404 under /soorten-fotoshoots/ also offers a link back
to the overview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 14:43:43 +01:00
co-authored by Claude Opus 5.5
parent e5f4348178
commit 7af2069959
84 changed files with 6090 additions and 128 deletions
@@ -0,0 +1,28 @@
import { chakra } from '@chakra-ui/react';
// A small chevron for the submenu toggles. Decorative: the button carries the
// name and aria-expanded. It turns upside down while its button has
// `data-open`; with reduced motion it jumps instead of turning (BR-NAV-42).
export default function ChevronIcon() {
return (
<chakra.svg
viewBox="0 0 12 12"
width="12px"
height="12px"
aria-hidden="true"
focusable="false"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
transitionProperty="transform"
transitionDuration="swap"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
css={{ '[data-open] > &': { transform: 'rotate(180deg)' } }}
>
<path d="M2 4.25 6 8l4-3.75" />
</chakra.svg>
);
}
@@ -0,0 +1,177 @@
import { screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe';
import { cssRulesFor } from '@/test/cssRules';
import { mockViewport } from '@/test/navViewport';
import { renderWithProviders } from '@/test/renderWithProviders';
import NavigationBar from './NavigationBar';
const GROUP = 'Submenu Soorten fotoshoots';
// The mobile layout (below lg) through the whole navigation bar
async function renderMobile(path = '/contact') {
mockViewport(375);
const result = await renderWithProviders(<NavigationBar />, { path });
return { ...result, user: userEvent.setup() };
}
const hamburger = () => screen.getByTestId('nav-menu-toggle');
const menu = () => document.getElementById('mobile-nav')!;
const inMenu = () => within(menu());
const groupToggle = () => inMenu().getByRole('button', { name: GROUP });
const subLinks = () => ['Newborn', 'Zwangerschap', 'Gezin'];
async function openMenu(path?: string) {
const rendered = await renderMobile(path);
await rendered.user.click(hamburger());
return rendered;
}
describe('MobileNav', () => {
it('opens with the hamburger and shows the main items', async () => {
await openMenu();
expect(hamburger()).toHaveAttribute('aria-expanded', 'true');
expect(hamburger()).toHaveAccessibleName('Menu sluiten');
for (const name of ['Home', 'Over mij', 'Portfolio', 'Contact']) {
expect(inMenu().getByRole('link', { name })).toBeVisible();
}
});
it('keeps the menu out of reach while closed', async () => {
await renderMobile();
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
expect(
within(menu()).queryByRole('link', { name: 'Contact' }),
).toBeNull();
});
it('starts with the group collapsed outside the section (BR-NAV-31)', async () => {
await openMenu('/contact');
expect(groupToggle()).toHaveAttribute('aria-expanded', 'false');
});
it.each(['/soorten-fotoshoots', '/soorten-fotoshoots/gezin'])(
'starts with the group expanded on %s (BR-NAV-31)',
async (path) => {
await openMenu(path);
expect(groupToggle()).toHaveAttribute('aria-expanded', 'true');
for (const name of subLinks()) {
expect(inMenu().getByRole('link', { name })).toBeVisible();
}
},
);
it('flips the group with the chevron and hides collapsed links (BR-NAV-36)', async () => {
const { user } = await openMenu('/contact');
expect(groupToggle()).toHaveAttribute(
'aria-controls',
'mobile-group-soorten-fotoshoots',
);
for (const name of subLinks()) {
expect(inMenu().queryByRole('link', { name })).toBeNull();
}
await user.click(groupToggle());
expect(groupToggle()).toHaveAttribute('aria-expanded', 'true');
for (const name of subLinks()) {
expect(inMenu().getByRole('link', { name })).toBeVisible();
}
await user.click(groupToggle());
expect(groupToggle()).toHaveAttribute('aria-expanded', 'false');
expect(inMenu().queryByRole('link', { name: 'Gezin' })).toBeNull();
});
it('is not reached by Tab while the group is collapsed', async () => {
const { user } = await openMenu('/contact');
const reached: string[] = [];
for (let i = 0; i < 10; i += 1) {
await user.tab();
reached.push(document.activeElement?.textContent ?? '');
}
for (const name of subLinks()) expect(reached).not.toContain(name);
});
it.each(['Contact', 'Soorten fotoshoots'])(
'closes the whole menu when %s is chosen (BR-NAV-32)',
async (name) => {
const { user } = await openMenu('/contact');
await user.click(inMenu().getByRole('link', { name }));
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
expect(hamburger()).toHaveAccessibleName('Menu openen');
},
);
it('closes the whole menu when a sub-link is chosen', async () => {
const { user } = await openMenu('/soorten-fotoshoots');
await user.click(inMenu().getByRole('link', { name: 'Gezin' }));
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
});
it('closes with the hamburger itself', async () => {
const { user } = await openMenu();
await user.click(hamburger());
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
});
it('closes with Escape and puts the focus on the hamburger (BR-NAV-33)', async () => {
const { user } = await openMenu();
inMenu().getByRole('link', { name: 'Portfolio' }).focus();
await user.keyboard('{Escape}');
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
expect(hamburger()).toHaveFocus();
});
it('also returns the focus to the hamburger when Escape is pressed on it', async () => {
const { user } = await openMenu();
expect(hamburger()).toHaveFocus();
await user.keyboard('{Escape}');
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
expect(hamburger()).toHaveFocus();
});
it('does not move the focus on Escape when it was elsewhere', async () => {
const { user } = await openMenu();
(document.activeElement as HTMLElement).blur();
await user.keyboard('{Escape}');
expect(hamburger()).toHaveAttribute('aria-expanded', 'false');
expect(hamburger()).not.toHaveFocus();
});
it('scrolls inside the screen and centres short content (BR-NAV-34)', async () => {
await openMenu();
expect(getComputedStyle(menu()).overflowY).toBe('auto');
const rules = cssRulesFor(menu()).join('\n');
expect(rules).toContain('overscroll-behavior');
const centring = menu().firstElementChild!;
expect(cssRulesFor(centring).join('\n')).toContain('margin-block');
expect(centring.querySelector('nav')).not.toBeNull();
});
it('locks the page behind it while open and restores it after', async () => {
const { user } = await openMenu();
expect(document.body.style.overflow).toBe('hidden');
await user.click(hamburger());
expect(document.body.style.overflow).toBe('');
});
it('has no axe violations open, collapsed and expanded', async () => {
const { container, user } = await openMenu('/contact');
expect(await axeResults(container)).toHaveNoViolations();
await user.click(groupToggle());
expect(await axeResults(container)).toHaveNoViolations();
});
it('removes the transitions with reduced motion (BR-NAV-42)', async () => {
await openMenu('/soorten-fotoshoots');
const group = document.getElementById(
'mobile-group-soorten-fotoshoots',
)!;
for (const element of [menu(), group]) {
const rules = cssRulesFor(element).join('\n');
expect(rules).toContain('prefers-reduced-motion: reduce');
expect(rules).toContain('transition: none');
}
});
});
+68 -27
View File
@@ -1,22 +1,43 @@
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
import { Box, Stack } from '@chakra-ui/react';
import { mainNav } from '@/navigation';
import type { NavMenuEvent } from '@/lib/navMenuState';
import { hasChildren, mainNav } from '@/navigation';
import RouterLink from '../RouterLink';
import MobileNavGroup from './MobileNavGroup';
type MobileNavProps = {
id: string;
open: boolean;
onClose: () => void;
// The sub-list of the item with children is expanded
groupOpen: boolean;
pathname: string;
dispatch: (event: NavMenuEvent) => void;
};
// Menu onder de navigatiebalk op mobiel, vult de rest van het scherm
export default function MobileNav({ id, open, onClose }: MobileNavProps) {
// Pagina eronder niet laten scrollen, en sluiten met Escape
export default function MobileNav({
id,
open,
groupOpen,
pathname,
dispatch,
}: MobileNavProps) {
const box = useRef<HTMLDivElement>(null);
// Pagina eronder niet laten scrollen, en sluiten met Escape. De focus gaat
// terug naar de hamburger als die in het menu of op de hamburger stond
// (de hamburger herken je aan aria-controls naar dit menu).
useEffect(() => {
if (!open) return;
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') onClose();
if (event.key !== 'Escape') return;
const active = document.activeElement;
const focusInside =
!!active &&
(!!box.current?.contains(active) ||
active.getAttribute('aria-controls') === id);
dispatch({ type: 'escape', focusInside });
};
document.body.style.overflow = 'hidden';
document.addEventListener('keydown', onKeyDown);
@@ -25,10 +46,11 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
document.body.style.overflow = '';
document.removeEventListener('keydown', onKeyDown);
};
}, [open, onClose]);
}, [open, id, dispatch]);
return (
<Box
ref={box}
id={id}
position="fixed"
top="header"
@@ -38,7 +60,9 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
zIndex="mobileNav"
display={{ base: 'flex', lg: 'none' }}
flexDirection="column"
justifyContent="center"
// Een hoog menu scrolt binnen het scherm (BR-NAV-34)
overflowY="auto"
overscrollBehavior="contain"
pt={8}
pb={16}
px="gutter"
@@ -49,26 +73,43 @@ export default function MobileNav({ id, open, onClose }: MobileNavProps) {
transitionProperty="clip-path, visibility"
transitionDuration="interaction"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
>
<nav aria-label="Mobiel menu">
<Stack as="ul" gap={5} listStyleType="none">
{mainNav.map((item) => (
<li key={item.to}>
<RouterLink
to={item.to}
onClick={onClose}
display="block"
fontFamily="heading"
fontSize="1.9rem"
color="ink"
_currentPage={{ color: 'accent' }}
>
{item.label}
</RouterLink>
</li>
))}
</Stack>
</nav>
{/* Automatische marges centreren een kort menu en laten een hoog
menu bovenaan beginnen (centreren zou de bovenkant afknippen) */}
<Box marginBlock="auto">
<nav aria-label="Mobiel menu">
<Stack as="ul" gap={5} listStyleType="none">
{mainNav.map((item) => (
<li key={item.to}>
{hasChildren(item) ? (
<MobileNavGroup
item={item}
id={`mobile-group-${item.to.slice(1)}`}
open={groupOpen}
pathname={pathname}
dispatch={dispatch}
/>
) : (
<RouterLink
to={item.to}
onClick={() =>
dispatch({ type: 'linkChosen' })
}
display="block"
fontFamily="heading"
fontSize="1.9rem"
color="ink"
_currentPage={{ color: 'accent' }}
>
{item.label}
</RouterLink>
)}
</li>
))}
</Stack>
</nav>
</Box>
</Box>
);
}
@@ -0,0 +1,113 @@
import { Box, chakra, Flex } from '@chakra-ui/react';
import { isSectionCurrent } from '@/lib/navCurrent';
import type { NavMenuEvent } from '@/lib/navMenuState';
import type { NavItem } from '@/navigation';
import RouterLink from '../RouterLink';
import ChevronIcon from './ChevronIcon';
type MobileNavGroupProps = {
item: NavItem & { children: readonly NavItem[] };
// Id of the sub-list, for aria-controls
id: string;
open: boolean;
pathname: string;
dispatch: (event: NavMenuEvent) => void;
};
// Exact: only the page itself is current (BR-NAV-01), also with a query
const exactActive = { exact: true, includeSearch: false } as const;
const duration = '0.3s';
const easing = 'cubic-bezier(.22, .61, .36, 1)';
// The parent row of the mobile menu: the link to the overview, a chevron
// button and an expandable list of sub-pages (BR-NAV-30..36)
export default function MobileNavGroup({
item,
id,
open,
pathname,
dispatch,
}: MobileNavGroupProps) {
return (
<>
<Flex alignItems="center" gap={1}>
<RouterLink
to={item.to}
activeOptions={exactActive}
onClick={() => dispatch({ type: 'linkChosen' })}
display="block"
fontFamily="heading"
fontSize="1.9rem"
color={isSectionCurrent(item, pathname) ? 'accent' : 'ink'}
_currentPage={{ color: 'accent' }}
>
{item.label}
</RouterLink>
<chakra.button
type="button"
aria-expanded={open}
aria-controls={id}
aria-label={`Submenu ${item.label}`}
data-open={open || undefined}
display="flex"
alignItems="center"
justifyContent="center"
// 44px: minimaal klikdoel op touch (BR-NAV-40)
w="44px"
h="44px"
flexShrink={0}
cursor="pointer"
color="ink"
onClick={() => dispatch({ type: 'toggleGroup' })}
>
<ChevronIcon />
</chakra.button>
</Flex>
{/* Grid rows 0fr to 1fr animate the height without measuring. On
close the visibility switches only after the collapse, so the
collapse is seen; collapsed links are neither focusable nor
read (BR-NAV-36). */}
<Box
id={id}
display="grid"
gridTemplateRows={open ? '1fr' : '0fr'}
visibility={open ? 'visible' : 'hidden'}
transition={`grid-template-rows ${duration} ${easing}, visibility 0s linear ${open ? '0s' : duration}`}
_motionReduce={{ transition: 'none' }}
>
<Box overflow="hidden" minH={0}>
<chakra.ul
listStyleType="none"
pl="1.25rem"
pt={2}
display="flex"
flexDirection="column"
>
{item.children.map((child) => (
<li key={child.to}>
<RouterLink
to={child.to}
activeOptions={exactActive}
onClick={() =>
dispatch({ type: 'linkChosen' })
}
display="flex"
alignItems="center"
minH="44px"
fontFamily="heading"
fontSize="1.4rem"
color="ink"
// accent.deep: 1.4rem is not large text
_currentPage={{ color: 'accent.deep' }}
>
{child.label}
</RouterLink>
</li>
))}
</chakra.ul>
</Box>
</Box>
</>
);
}
@@ -0,0 +1,63 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { cssRulesFor } from '@/test/cssRules';
import { renderWithProviders } from '@/test/renderWithProviders';
import NavLink from './NavLink';
describe('NavLink', () => {
it('marks the section without aria-current', async () => {
await renderWithProviders(
<NavLink
to="/soorten-fotoshoots"
activeOptions={{ exact: true, includeSearch: false }}
sectionCurrent
>
Soorten
</NavLink>,
{ path: '/soorten-fotoshoots/newborn' },
);
const link = screen.getByRole('link', { name: 'Soorten' });
expect(link).toHaveAttribute('data-section-current');
expect(link).not.toHaveAttribute('aria-current');
});
it('sets no section mark by default or when false', async () => {
await renderWithProviders(
<>
<NavLink to="/portfolio">Plain</NavLink>
<NavLink to="/contact" sectionCurrent={false}>
Off
</NavLink>
</>,
);
for (const name of ['Plain', 'Off']) {
expect(screen.getByRole('link', { name })).not.toHaveAttribute(
'data-section-current',
);
}
});
it('still lets the router set aria-current on the current page', async () => {
await renderWithProviders(
<NavLink to="/portfolio">Portfolio</NavLink>,
{
path: '/portfolio',
},
);
expect(screen.getByRole('link')).toHaveAttribute(
'aria-current',
'page',
);
});
it('draws the underline for the section mark too', async () => {
await renderWithProviders(
<NavLink to="/soorten-fotoshoots" sectionCurrent>
Soorten
</NavLink>,
);
const rules = cssRulesFor(screen.getByRole('link')).join('\n');
expect(rules).toContain('[data-section-current]::after');
expect(rules).toContain('[aria-current="page"]::after');
});
});
+12 -3
View File
@@ -1,8 +1,16 @@
import RouterLink from '../RouterLink';
type NavLinkProps = React.ComponentProps<typeof RouterLink>;
type NavLinkProps = React.ComponentProps<typeof RouterLink> & {
// The page is below this link (a shoot page below the overview): shows
// the same underline as the current page, without aria-current
sectionCurrent?: boolean;
};
export default function NavLink({ children, ...props }: NavLinkProps) {
export default function NavLink({
children,
sectionCurrent,
...props
}: NavLinkProps) {
return (
<RouterLink
textStyle="eyebrow"
@@ -11,6 +19,7 @@ export default function NavLink({ children, ...props }: NavLinkProps) {
display="inline-block"
py="2"
mx="4"
data-section-current={sectionCurrent ? '' : undefined}
css={{
'&::after': {
content: '""',
@@ -26,7 +35,7 @@ export default function NavLink({ children, ...props }: NavLinkProps) {
transitionDuration: 'interaction',
transitionTimingFunction: 'smooth',
},
'&:hover::after, &:focus-visible::after, &[aria-current="page"]::after':
'&:hover::after, &:focus-visible::after, &[aria-current="page"]::after, &[data-section-current]::after':
{
transform: 'scaleX(1)',
transformOrigin: 'left',
@@ -0,0 +1,158 @@
import { createRef } from 'react';
import { fireEvent, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import { hasChildren, mainNav } from '@/navigation';
import { renderWithProviders } from '@/test/renderWithProviders';
import NavSubmenu from './NavSubmenu';
const item = mainNav.find(hasChildren)!;
const TOGGLE = 'Submenu Soorten fotoshoots';
// The component alone with a fake dispatch: what it reports, not what the
// reducer does with it
async function renderSubmenu({
open = false,
path = '/',
transparent = false,
} = {}) {
const dispatch = vi.fn();
const toggleRef = createRef<HTMLButtonElement>();
await renderWithProviders(
<>
<NavSubmenu
item={item}
id="submenu-soorten-fotoshoots"
open={open}
pathname={path}
transparent={transparent}
toggleRef={toggleRef}
dispatch={dispatch}
/>
<button>elsewhere</button>
</>,
{ path },
);
return { dispatch, toggleRef, user: userEvent.setup() };
}
const toggle = () => screen.getByRole('button', { name: TOGGLE });
describe('NavSubmenu', () => {
it('renders without errors with the real main menu item', async () => {
await renderSubmenu();
expect(
screen.getByRole('link', { name: 'Soorten fotoshoots' }),
).toHaveAttribute('href', '/soorten-fotoshoots');
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
});
it('passes the toggle element to toggleRef', async () => {
const { toggleRef } = await renderSubmenu();
expect(toggleRef.current).toBe(toggle());
});
it('reflects open in aria-expanded and data-open', async () => {
await renderSubmenu({ open: true });
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
expect(toggle()).toHaveAttribute('data-open');
});
it('reports toggleSubmenu for a click on the toggle', async () => {
const { dispatch, user } = await renderSubmenu();
await user.click(toggle());
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
type: 'toggleSubmenu',
});
});
it('reports linkChosen for a click on a panel link', async () => {
const { dispatch, user } = await renderSubmenu({ open: true });
await user.click(screen.getByRole('link', { name: 'Gezin' }));
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
type: 'linkChosen',
});
});
it('reports escape with focusInside true when focus is in the submenu', async () => {
const { dispatch, user } = await renderSubmenu({ open: true });
toggle().focus();
await user.keyboard('{Escape}');
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
type: 'escape',
focusInside: true,
});
});
it('reports escape with focusInside false when focus is elsewhere', async () => {
const { dispatch, user } = await renderSubmenu({ open: true });
screen.getByRole('button', { name: 'elsewhere' }).focus();
await user.keyboard('{Escape}');
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
type: 'escape',
focusInside: false,
});
});
it('reports outside for a pointer down outside, not inside', async () => {
const { dispatch } = await renderSubmenu({ open: true });
fireEvent.pointerDown(toggle());
expect(dispatch).not.toHaveBeenCalled();
fireEvent.pointerDown(
screen.getByRole('button', { name: 'elsewhere' }),
);
expect(dispatch).toHaveBeenCalledExactlyOnceWith({ type: 'outside' });
});
it('listens for Escape and outside only while open', async () => {
const { dispatch, user } = await renderSubmenu({ open: false });
await user.keyboard('{Escape}');
fireEvent.pointerDown(
screen.getByRole('button', { name: 'elsewhere' }),
);
expect(dispatch).not.toHaveBeenCalled();
});
it('reports focusLeave when focus moves to an element outside', async () => {
const { dispatch } = await renderSubmenu({ open: true });
fireEvent.focusOut(toggle(), {
relatedTarget: screen.getByRole('button', { name: 'elsewhere' }),
});
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
type: 'focusLeave',
});
});
it('ignores focus that stays inside or has no target', async () => {
const { dispatch } = await renderSubmenu({ open: true });
fireEvent.focusOut(toggle(), {
relatedTarget: screen.getByRole('link', { name: 'Newborn' }),
});
fireEvent.focusOut(toggle(), { relatedTarget: null });
expect(dispatch).not.toHaveBeenCalled();
});
it('reports nothing for hover or arrow keys (BR-NAV-21, BR-NAV-27)', async () => {
const { dispatch, user } = await renderSubmenu({ open: true });
await user.hover(toggle());
await user.hover(screen.getByRole('link', { name: 'Gezin' }));
screen.getByRole('link', { name: 'Gezin' }).focus();
await user.keyboard(
'{ArrowDown}{ArrowUp}{ArrowLeft}{ArrowRight}{Home}{End}',
);
expect(dispatch).not.toHaveBeenCalled();
});
it('marks the shoot page in the panel and the section on the parent', async () => {
await renderSubmenu({ open: true, path: '/soorten-fotoshoots/gezin' });
expect(screen.getByRole('link', { name: 'Gezin' })).toHaveAttribute(
'aria-current',
'page',
);
const parent = screen.getByRole('link', {
name: 'Soorten fotoshoots',
});
expect(parent).not.toHaveAttribute('aria-current');
expect(parent).toHaveAttribute('data-section-current');
});
});
@@ -0,0 +1,162 @@
import { useRef, type RefObject } from 'react';
import { Box, chakra } from '@chakra-ui/react';
import useDismiss from '@/hooks/useDismiss';
import { isSectionCurrent } from '@/lib/navCurrent';
import type { NavMenuEvent } from '@/lib/navMenuState';
import type { NavItem } from '@/navigation';
import RouterLink from '../RouterLink';
import ChevronIcon from './ChevronIcon';
import NavLink from './NavLink';
type NavSubmenuProps = {
item: NavItem & { children: readonly NavItem[] };
// Id of the panel, for aria-controls
id: string;
open: boolean;
pathname: string;
// The header is see-through over the home hero (white text)
transparent: boolean;
toggleRef: RefObject<HTMLButtonElement | null>;
dispatch: (event: NavMenuEvent) => void;
};
// Exact: only the page itself is current, not the pages below it (BR-NAV-01);
// without the query, so a filter in the URL does not switch it off
const exactActive = { exact: true, includeSearch: false } as const;
// Desktop submenu: the parent stays a link, a separate toggle opens a panel
// with the sub-pages. Disclosure navigation: no role="menu", no arrow keys,
// no hover opening (BR-NAV-21, BR-NAV-27).
export default function NavSubmenu({
item,
id,
open,
pathname,
transparent,
toggleRef,
dispatch,
}: NavSubmenuProps) {
const wrapper = useRef<HTMLDivElement>(null);
useDismiss(wrapper, open, (reason) =>
dispatch(
reason === 'escape'
? {
type: 'escape',
focusInside:
wrapper.current?.contains(document.activeElement) ??
false,
}
: { type: 'outside' },
),
);
return (
<Box
ref={wrapper}
position="relative"
display="flex"
alignItems="center"
// Focus moving to something outside closes the panel; a blur
// without a target (window blur) is ignored (BR-NAV-25)
onBlur={(event) => {
const next = event.relatedTarget;
if (
next instanceof Node &&
!event.currentTarget.contains(next)
) {
dispatch({ type: 'focusLeave' });
}
}}
>
<NavLink
to={item.to}
activeOptions={exactActive}
sectionCurrent={isSectionCurrent(item, pathname)}
mr={0}
>
{item.label}
</NavLink>
<chakra.button
ref={toggleRef}
type="button"
aria-expanded={open}
aria-controls={id}
aria-label={`Submenu ${item.label}`}
data-open={open || undefined}
display="flex"
alignItems="center"
justifyContent="center"
// 44px: minimaal klikdoel op touch (BR-NAV-40)
w="44px"
h="44px"
cursor="pointer"
color="currentColor"
// Over the hero the header is dark: a white ring (BR-NAV-43)
css={
transparent ? { '--focus-ring-color': 'white' } : undefined
}
onClick={() => dispatch({ type: 'toggleSubmenu' })}
>
<ChevronIcon />
</chakra.button>
<Box
id={id}
position="absolute"
top="calc(100% + 0.75rem)"
left="4"
minW="15rem"
// Own colours, so the panel is solid also over the hero (BR-NAV-29)
bg="bg"
color="fg"
borderWidth="1px"
borderColor="line"
shadow="panel"
// Hidden from sight and from Tab and screen readers while
// closed, but kept in the DOM so aria-controls stays valid
visibility={open ? 'visible' : 'hidden'}
opacity={open ? 1 : 0}
transform={open ? 'none' : 'translateY(-6px)'}
pointerEvents={open ? 'auto' : 'none'}
transitionProperty="opacity, transform, visibility"
transitionDuration="swap"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
>
<chakra.ul listStyleType="none" py="2">
{item.children.map((child) => (
<li key={child.to}>
<RouterLink
to={child.to}
activeOptions={exactActive}
onClick={() => dispatch({ type: 'linkChosen' })}
textStyle="eyebrow"
color="fg"
display="flex"
alignItems="center"
minH="44px"
px="5"
position="relative"
_hover={{ bg: 'paper.alt' }}
_currentPage={{
color: 'accent.deep',
_before: {
content: '""',
position: 'absolute',
left: 0,
top: 0,
bottom: 0,
width: '2px',
bg: 'accent',
},
}}
>
{child.label}
</RouterLink>
</li>
))}
</chakra.ul>
</Box>
</Box>
);
}
@@ -1,9 +1,30 @@
import { screen, within } from '@testing-library/react';
import { fireEvent, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe';
import { cssRulesFor } from '@/test/cssRules';
import { mockViewport } from '@/test/navViewport';
import { renderWithProviders } from '@/test/renderWithProviders';
import NavigationBar from './NavigationBar';
const TOGGLE = 'Submenu Soorten fotoshoots';
const SHOOTS = ['Newborn', 'Zwangerschap', 'Gezin', 'Loveshoot', 'Portretten'];
// The desktop layout (lg and up) unless a width is given
async function renderBar(path = '/', width = 1280) {
mockViewport(width);
const result = await renderWithProviders(<NavigationBar />, { path });
return { ...result, user: userEvent.setup() };
}
const toggle = () => screen.getByRole('button', { name: TOGGLE });
const panel = () => document.getElementById('submenu-soorten-fotoshoots')!;
// By text: the name of a link in a closed (hidden) panel is empty
const panelLink = (text: string) =>
within(panel())
.getAllByRole('link', { hidden: true })
.find((link) => link.textContent === text)!;
describe('NavigationBar', () => {
it('heeft het logo als link naar home', async () => {
await renderWithProviders(<NavigationBar />, { path: '/portfolio' });
@@ -15,12 +36,11 @@ describe('NavigationBar', () => {
});
it('toont het hoofdmenu in de vaste volgorde', async () => {
const { container } = await renderWithProviders(<NavigationBar />);
const { container } = await renderBar();
const nav = screen.getByRole('navigation', { name: 'Hoofdmenu' });
const topLevel = [...nav.querySelectorAll(':scope > ul > li')];
expect(
within(nav)
.getAllByRole('link', { hidden: true })
.map((link) => link.textContent),
topLevel.map((li) => li.querySelector('a')?.textContent),
).toEqual([
'Home',
'Over mij',
@@ -28,6 +48,11 @@ describe('NavigationBar', () => {
'Soorten fotoshoots',
'Contact',
]);
expect(
within(panel())
.getAllByRole('link', { hidden: true })
.map((link) => link.textContent),
).toEqual(SHOOTS);
expect(await axeResults(container)).toHaveNoViolations();
});
@@ -38,3 +63,222 @@ describe('NavigationBar', () => {
);
});
});
describe('NavigationBar submenu', () => {
it('heeft een knop met vaste naam, aria-expanded en een bestaand paneel', async () => {
await renderBar();
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
expect(toggle()).toHaveAttribute(
'aria-controls',
'submenu-soorten-fotoshoots',
);
expect(panel()).toBeInTheDocument();
});
it('opent met een klik en meldt dat in aria-expanded', async () => {
const { user } = await renderBar();
await user.click(toggle());
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
expect(toggle()).toHaveAccessibleName(TOGGLE);
for (const name of SHOOTS) {
expect(screen.getByRole('link', { name })).toBeVisible();
}
});
it.each(['{Enter}', ' '])('opent met toets %j', async (key) => {
const { user } = await renderBar();
toggle().focus();
await user.keyboard(key);
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
});
it('opent niet bij hoveren (BR-NAV-21)', async () => {
const { user } = await renderBar();
await user.hover(toggle());
await user.hover(
screen.getByRole('link', { name: 'Soorten fotoshoots' }),
);
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
});
it('sluit met Escape en zet de focus op de knop als die binnen stond (BR-NAV-23)', async () => {
const { user } = await renderBar();
await user.click(toggle());
await user.tab();
expect(document.activeElement).toBe(panelLink('Newborn'));
await user.keyboard('{Escape}');
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
expect(document.activeElement).toBe(toggle());
});
it('laat de focus staan bij Escape als die buiten het submenu stond', async () => {
const { user } = await renderBar();
await user.click(toggle());
toggle().blur();
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
await user.keyboard('{Escape}');
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
expect(document.activeElement).not.toBe(toggle());
});
it('sluit bij een pointer-down buiten zonder de focus te verplaatsen (BR-NAV-24)', async () => {
const { user } = await renderBar();
await user.click(toggle());
fireEvent.pointerDown(document.body);
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
expect(document.activeElement).toBe(toggle());
});
it('blijft open bij een pointer-down binnen het paneel', async () => {
const { user } = await renderBar();
await user.click(toggle());
fireEvent.pointerDown(panelLink('Gezin'));
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
});
it('sluit als Tab de focus uit het laatste paneellink haalt (BR-NAV-25)', async () => {
const { user } = await renderBar();
await user.click(toggle());
panelLink('Portretten').focus();
await user.tab();
expect(screen.getByRole('link', { name: 'Contact' })).toHaveFocus();
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
});
it('blijft open bij een focusout zonder doel, zoals een venster-blur', async () => {
const { user } = await renderBar();
await user.click(toggle());
fireEvent.focusOut(toggle(), { relatedTarget: null });
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
});
it('blijft open als de focus binnen het submenu verschuift', async () => {
const { user } = await renderBar();
await user.click(toggle());
await user.tab();
await user.tab();
expect(panelLink('Zwangerschap')).toHaveFocus();
expect(toggle()).toHaveAttribute('aria-expanded', 'true');
});
it('houdt de links van een gesloten paneel buiten bereik van rolzoeker en Tab (BR-NAV-28)', async () => {
const { user } = await renderBar();
for (const name of SHOOTS) {
expect(screen.queryByRole('link', { name })).toBeNull();
}
const reached: string[] = [];
for (let i = 0; i < 8; i += 1) {
await user.tab();
reached.push(document.activeElement?.textContent ?? '');
}
for (const name of SHOOTS) expect(reached).not.toContain(name);
await user.click(toggle());
for (const name of SHOOTS) {
expect(screen.getByRole('link', { name })).toBeVisible();
}
});
it('sluit na het kiezen van een link', async () => {
const { user } = await renderBar();
await user.click(toggle());
await user.click(screen.getByRole('link', { name: 'Gezin' }));
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
});
it('sluit weer met een tweede klik en laat de focus op de knop', async () => {
const { user } = await renderBar();
await user.click(toggle());
await user.click(toggle());
expect(toggle()).toHaveAttribute('aria-expanded', 'false');
expect(toggle()).toHaveFocus();
});
it('gebruikt geen menu-rollen (disclosure, geen menu)', async () => {
const { user } = await renderBar();
await user.click(toggle());
expect(
document.querySelector('[role="menu"], [role="menuitem"]'),
).toBeNull();
});
it('heeft geen axe-fouten met het paneel dicht en open', async () => {
const { container, user } = await renderBar();
expect(await axeResults(container)).toHaveNoViolations();
await user.click(toggle());
expect(await axeResults(container)).toHaveNoViolations();
});
it('zet de eigen kleuren op het paneel en currentColor op de knop (BR-NAV-29)', async () => {
await renderBar('/');
const panelRules = cssRulesFor(panel()).join('\n');
expect(panelRules).toMatch(/background(-color)?:/);
const toggleRules = cssRulesFor(toggle()).join('\n');
expect(toggleRules.toLowerCase()).toContain('color: currentcolor');
// Over de hero is de header doorzichtig: witte focusring (BR-NAV-43)
expect(toggleRules).toContain('--focus-ring-color: white');
});
it('zet de witte focusring niet op een effen header', async () => {
await renderBar('/portfolio');
expect(cssRulesFor(toggle()).join('\n')).not.toContain(
'--focus-ring-color: white',
);
});
it('zet bij voorkeur voor minder beweging geen overgang (BR-NAV-42)', async () => {
await renderBar();
const panelRules = cssRulesFor(panel()).join('\n');
expect(panelRules).toContain('prefers-reduced-motion: reduce');
expect(panelRules).toContain('transition: none');
const chevron = toggle().querySelector('svg')!;
const chevronRules = cssRulesFor(chevron).join('\n');
expect(chevronRules).toContain('prefers-reduced-motion: reduce');
expect(chevronRules).toContain('transition: none');
});
it('draait de pijl open via data-open (rotatie 180 graden)', async () => {
const { user } = await renderBar();
const chevron = toggle().querySelector('svg')!;
expect(cssRulesFor(chevron).join('\n')).toContain('rotate(180deg)');
expect(toggle()).not.toHaveAttribute('data-open');
await user.click(toggle());
expect(toggle()).toHaveAttribute('data-open');
});
});
describe('NavigationBar current page', () => {
it('markeert op een shootpagina het paneellink en alleen de sectie bij het hoofditem', async () => {
await renderBar('/soorten-fotoshoots/newborn');
expect(panelLink('Newborn')).toHaveAttribute('aria-current', 'page');
for (const name of SHOOTS.slice(1)) {
expect(panelLink(name)).not.toHaveAttribute('aria-current');
}
const parent = screen.getByRole('link', {
name: 'Soorten fotoshoots',
});
expect(parent).not.toHaveAttribute('aria-current');
expect(parent).toHaveAttribute('data-section-current');
});
it('markeert op het overzicht het hoofditem met beide', async () => {
await renderBar('/soorten-fotoshoots');
const parent = screen.getByRole('link', {
name: 'Soorten fotoshoots',
});
expect(parent).toHaveAttribute('aria-current', 'page');
expect(parent).toHaveAttribute('data-section-current');
for (const name of SHOOTS) {
expect(panelLink(name)).not.toHaveAttribute('aria-current');
}
});
it('markeert op een andere pagina het hoofditem niet', async () => {
await renderBar('/portfolio');
const parent = screen.getByRole('link', {
name: 'Soorten fotoshoots',
});
expect(parent).not.toHaveAttribute('data-section-current');
expect(parent).not.toHaveAttribute('aria-current');
});
});
@@ -8,32 +8,65 @@ import {
} from '@chakra-ui/react';
import NavLink from './NavLink';
import MobileNav from './MobileNav';
import { mainNav } from '@/navigation';
import NavSubmenu from './NavSubmenu';
import { hasChildren, mainNav } from '@/navigation';
import RouterLink from '../RouterLink';
import useScrolledPast from '@/hooks/useScrolledPast';
import { useCallback, useState } from 'react';
import { isSectionCurrent } from '@/lib/navCurrent';
import { initialNavMenuState, navMenuReducer } from '@/lib/navMenuState';
import { useEffect, useReducer, useRef } from 'react';
import { useRouterState } from '@tanstack/react-router';
// Images
import logoLight from '../../assets/logo-light.png';
import logoDark from '../../assets/logo-dark.png';
// Het item met een submenu: bepaalt of het mobiele menu open start in een sectie
const parentItem = mainNav.find(hasChildren);
export default function NavigationBar() {
const [open, setOpen] = useState(false);
const closeMenu = useCallback(() => setOpen(false), []);
// Eén reducer voor het mobiele menu, de groep en het desktop-submenu, zodat
// ze elkaar niet tegenspreken
const [state, dispatch] = useReducer(navMenuReducer, initialNavMenuState);
const hamburgerRef = useRef<HTMLButtonElement>(null);
const submenuToggleRef = useRef<HTMLButtonElement>(null);
// Het mobiele menu bestaat alleen onder lg; wordt het scherm breder, dan
// telt het als dicht.
// sluit de reducer het. Eerste render kan undefined geven: telt als mobiel.
const isDesktop = useBreakpointValue(
{ base: false, lg: true },
{ ssr: false },
);
const menuOpen = open && !isDesktop;
useEffect(() => {
dispatch({ type: 'viewport', isDesktop: !!isDesktop });
}, [isDesktop]);
const pathname = useRouterState({
select: (routerState) => routerState.location.pathname,
});
const isHome = pathname === '/';
// Elke wissel van pagina sluit de menu's (ook de terugknop), maar niet
// bij de eerste render
const previousPathname = useRef(pathname);
useEffect(() => {
if (previousPathname.current === pathname) return;
previousPathname.current = pathname;
dispatch({ type: 'routeChanged' });
}, [pathname]);
// De reducer vraagt om focus (na Escape); hier wordt die verplaatst
useEffect(() => {
if (!state.focusRequest) return;
const target =
state.focusRequest === 'menuToggle'
? hamburgerRef.current
: submenuToggleRef.current;
target?.focus();
dispatch({ type: 'focusHandled' });
}, [state.focusRequest]);
const pastHero = useScrolledPast(() => 150);
const isHome = useRouterState({
select: (state) => state.location.pathname === '/',
});
const isSolid = pastHero || !isHome;
// Doorzichtig over de hero, maar alleen op desktop. Op mobiel staat de
@@ -119,9 +152,21 @@ export default function NavigationBar() {
>
{mainNav.map((item) => (
<chakra.li key={item.to}>
<NavLink to={item.to}>
{item.label}
</NavLink>
{hasChildren(item) ? (
<NavSubmenu
item={item}
id={`submenu-${item.to.slice(1)}`}
open={state.submenuOpen}
pathname={pathname}
transparent={!isSolid}
toggleRef={submenuToggleRef}
dispatch={dispatch}
/>
) : (
<NavLink to={item.to}>
{item.label}
</NavLink>
)}
</chakra.li>
))}
</HStack>
@@ -134,13 +179,26 @@ export default function NavigationBar() {
justifyContent="flex-end"
>
<chakra.button
onClick={() => setOpen(!menuOpen)}
aria-label={
menuOpen ? 'Menu sluiten' : 'Menu openen'
ref={hamburgerRef}
onClick={() =>
dispatch({
type: 'toggleMenu',
inSection: parentItem
? isSectionCurrent(
parentItem,
pathname,
)
: false,
})
}
aria-expanded={menuOpen}
aria-label={
state.menuOpen
? 'Menu sluiten'
: 'Menu openen'
}
aria-expanded={state.menuOpen}
aria-controls="mobile-nav"
data-open={menuOpen || undefined}
data-open={state.menuOpen || undefined}
// Op desktop opent deze knop straks het info-menu (side area)
display={{ base: 'block', lg: 'none' }}
data-testid="nav-menu-toggle"
@@ -189,7 +247,13 @@ export default function NavigationBar() {
</Flex>
</Container>
</chakra.header>
<MobileNav id="mobile-nav" open={menuOpen} onClose={closeMenu} />
<MobileNav
id="mobile-nav"
open={state.menuOpen}
groupOpen={state.groupOpen}
pathname={pathname}
dispatch={dispatch}
/>
</>
);
}
@@ -0,0 +1,108 @@
import { cleanup, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { renderApp } from '@/test/renderApp';
import { renderWithProviders } from '@/test/renderWithProviders';
import RouterLink from '../RouterLink';
// Regression probe of the router's `activeOptions` (BR-NAV-01, BR-NAV-04).
// The facts pinned here decide why every nav and footer link gets
// `{ exact: true, includeSearch: false }`: a plain `exact` ignores a trailing
// slash but not letter case, and loses `aria-current` on any query string.
const bothVariants = [
['exact', { exact: true }],
['exact + includeSearch false', { exact: true, includeSearch: false }],
] as const;
async function currentOf(
variant: (typeof bothVariants)[number][1],
path: string,
) {
cleanup();
await renderWithProviders(
<>
<RouterLink to="/soorten-fotoshoots" activeOptions={variant}>
parent
</RouterLink>
<RouterLink
to="/soorten-fotoshoots/newborn"
activeOptions={variant}
>
child
</RouterLink>
</>,
{ path },
);
const isCurrent = (name: string) =>
screen.getByRole('link', { name }).getAttribute('aria-current') ===
'page';
return { parent: isCurrent('parent'), child: isCurrent('child') };
}
describe.each(bothVariants)('activeOptions %s', (_name, variant) => {
it('marks the exact path only', async () => {
expect(await currentOf(variant, '/soorten-fotoshoots')).toEqual({
parent: true,
child: false,
});
});
it('marks the child, not the parent, on the child path', async () => {
expect(await currentOf(variant, '/soorten-fotoshoots/newborn')).toEqual(
{ parent: false, child: true },
);
});
it('ignores a trailing slash', async () => {
expect(await currentOf(variant, '/soorten-fotoshoots/')).toEqual({
parent: true,
child: false,
});
expect(
await currentOf(variant, '/soorten-fotoshoots/newborn/'),
).toEqual({ parent: false, child: true });
});
it('does not ignore letter case', async () => {
expect(await currentOf(variant, '/Soorten-Fotoshoots/Newborn')).toEqual(
{ parent: false, child: false },
);
});
});
describe('activeOptions and the query string', () => {
it('plain exact loses aria-current when the URL has a query', async () => {
expect(
await currentOf({ exact: true }, '/soorten-fotoshoots?x=1'),
).toEqual({ parent: false, child: false });
});
it('includeSearch false keeps aria-current with a query', async () => {
expect(
await currentOf(
{ exact: true, includeSearch: false },
'/soorten-fotoshoots?x=1',
),
).toEqual({ parent: true, child: false });
});
it('includeSearch false keeps a non-matching page unmarked', async () => {
expect(
await currentOf(
{ exact: true, includeSearch: false },
'/portfolio?shoot=newborn',
),
).toEqual({ parent: false, child: false });
});
});
describe('activeOptions in the real route tree', () => {
it('renders the Newborn page on a case variant', async () => {
// The router matches case-insensitively, so the page shows; which
// links are current there is pinned in navSubmenu.test.tsx
await renderApp('/soorten-fotoshoots/Newborn');
expect(
await screen.findByRole('heading', { level: 1 }),
).toBeInTheDocument();
});
});