Adds the fallbacks for visitors without JavaScript
The mobile menu works through CSS, and controls that need JavaScript are hidden without it. The contact photo gets its own preload, and the tests cover the new Reveal behaviour, the first row and the noscript markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import type { NavMenuEvent } from '@/lib/navMenuState';
|
||||
import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import MobileNavGroup from './MobileNavGroup';
|
||||
import { NoScriptMenuClose } from './NoScriptNav';
|
||||
|
||||
// Exact, like the submenu: no link counts as current on an unknown URL
|
||||
// (BR-404-05)
|
||||
@@ -82,6 +83,7 @@ export default function MobileNav({
|
||||
{/* Automatische marges centreren een kort menu en laten een hoog
|
||||
menu bovenaan beginnen (centreren zou de bovenkant afknippen) */}
|
||||
<Box marginBlock="auto">
|
||||
<NoScriptMenuClose />
|
||||
<nav aria-label="Mobiel menu">
|
||||
<Stack as="ul" gap={5} listStyleType="none">
|
||||
{mainNav.map((item) => (
|
||||
|
||||
@@ -46,6 +46,7 @@ export default function MobileNavGroup({
|
||||
</RouterLink>
|
||||
<chakra.button
|
||||
type="button"
|
||||
data-requires-js
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
aria-label={`Submenu ${item.label}`}
|
||||
|
||||
@@ -54,6 +54,7 @@ export default function NavSubmenu({
|
||||
return (
|
||||
<Box
|
||||
ref={wrapper}
|
||||
data-submenu
|
||||
position="relative"
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
@@ -80,6 +81,7 @@ export default function NavSubmenu({
|
||||
<chakra.button
|
||||
ref={toggleRef}
|
||||
type="button"
|
||||
data-requires-js
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
aria-label={`Submenu ${item.label}`}
|
||||
@@ -102,6 +104,7 @@ export default function NavSubmenu({
|
||||
</chakra.button>
|
||||
<Box
|
||||
id={id}
|
||||
data-submenu-panel
|
||||
position="absolute"
|
||||
top="calc(100% + 0.75rem)"
|
||||
left="4"
|
||||
|
||||
@@ -8,10 +8,12 @@ import {
|
||||
} from '@chakra-ui/react';
|
||||
import NavLink from './NavLink';
|
||||
import MobileNav from './MobileNav';
|
||||
import { NoScriptMenuOpen } from './NoScriptNav';
|
||||
import NavSubmenu from './NavSubmenu';
|
||||
import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
|
||||
import { isSectionCurrent } from '@/lib/navCurrent';
|
||||
import { initialNavMenuState, navMenuReducer } from '@/lib/navMenuState';
|
||||
import { useEffect, useReducer, useRef } from 'react';
|
||||
@@ -79,6 +81,7 @@ export default function NavigationBar() {
|
||||
return (
|
||||
<>
|
||||
<chakra.header
|
||||
id={HEADER_ID}
|
||||
position="fixed"
|
||||
top={0}
|
||||
insetX={0}
|
||||
@@ -135,6 +138,9 @@ export default function NavigationBar() {
|
||||
alt=""
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
// Not shown on pages with a solid header, so
|
||||
// not fetched there (BR-PRE-05)
|
||||
loading={isHome ? undefined : 'lazy'}
|
||||
display={overlay('none', 'block')}
|
||||
/>
|
||||
</RouterLink>
|
||||
@@ -183,8 +189,10 @@ export default function NavigationBar() {
|
||||
display="flex"
|
||||
justifyContent="flex-end"
|
||||
>
|
||||
<NoScriptMenuOpen />
|
||||
<chakra.button
|
||||
ref={hamburgerRef}
|
||||
data-requires-js
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: 'toggleMenu',
|
||||
@@ -202,7 +210,7 @@ export default function NavigationBar() {
|
||||
: 'Menu openen'
|
||||
}
|
||||
aria-expanded={state.menuOpen}
|
||||
aria-controls="mobile-nav"
|
||||
aria-controls={MOBILE_NAV_ID}
|
||||
data-open={state.menuOpen || undefined}
|
||||
// Op desktop opent deze knop straks het info-menu (side area)
|
||||
display={{ base: 'block', lg: 'none' }}
|
||||
@@ -253,7 +261,7 @@ export default function NavigationBar() {
|
||||
</Container>
|
||||
</chakra.header>
|
||||
<MobileNav
|
||||
id="mobile-nav"
|
||||
id={MOBILE_NAV_ID}
|
||||
open={state.menuOpen}
|
||||
groupOpen={state.groupOpen}
|
||||
pathname={pathname}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { hydratePage, renderToString, serverHtml } from '@/test/hydrate';
|
||||
import NavigationBar from './NavigationBar';
|
||||
import { NoScriptMenuClose, NoScriptMenuOpen } from './NoScriptNav';
|
||||
|
||||
// The noscript wrappers are dropped first: this document runs scripts, so the
|
||||
// parser would keep their content as text
|
||||
function parse(markup: string) {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = markup.replaceAll(/<\/?noscript>/g, '');
|
||||
return container;
|
||||
}
|
||||
|
||||
const FOLLOWING = Node.DOCUMENT_POSITION_FOLLOWING;
|
||||
|
||||
describe('NoScriptMenuOpen', () => {
|
||||
it('renders one link to the panel inside a noscript', () => {
|
||||
const markup = renderToString(<NoScriptMenuOpen />);
|
||||
expect(markup.startsWith('<noscript>')).toBe(true);
|
||||
expect(markup.endsWith('</noscript>')).toBe(true);
|
||||
const links = parse(markup).querySelectorAll('a');
|
||||
expect(links).toHaveLength(1);
|
||||
expect(links[0]).toHaveAttribute('href', '#mobile-nav');
|
||||
expect(links[0]).toHaveAttribute('aria-label', 'Menu openen');
|
||||
expect(links[0]).toHaveAttribute('class', 'ns-menu-open');
|
||||
expect(links[0]).toHaveAttribute('data-testid', 'nav-noscript-open');
|
||||
expect(
|
||||
links[0].querySelectorAll('span[aria-hidden="true"]'),
|
||||
).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('has no style element inside the noscript', () => {
|
||||
expect(renderToString(<NoScriptMenuOpen />)).not.toContain('<style');
|
||||
});
|
||||
});
|
||||
|
||||
describe('NoScriptMenuClose', () => {
|
||||
it('renders one link to the header inside a noscript', () => {
|
||||
const markup = renderToString(<NoScriptMenuClose />);
|
||||
expect(markup.startsWith('<noscript>')).toBe(true);
|
||||
const links = parse(markup).querySelectorAll('a');
|
||||
expect(links).toHaveLength(1);
|
||||
expect(links[0]).toHaveAttribute('href', '#site-header');
|
||||
expect(links[0]).toHaveAttribute('class', 'ns-menu-close');
|
||||
expect(links[0]).toHaveAttribute('data-testid', 'nav-noscript-close');
|
||||
expect(links[0]).toHaveTextContent('Menu sluiten');
|
||||
});
|
||||
|
||||
it('has no style element inside the noscript', () => {
|
||||
expect(renderToString(<NoScriptMenuClose />)).not.toContain('<style');
|
||||
});
|
||||
});
|
||||
|
||||
describe('NavigationBar server markup', () => {
|
||||
it('puts the open link before the hamburger and the close link first in the panel', async () => {
|
||||
const navigation = parse(await serverHtml(<NavigationBar />));
|
||||
const open = navigation.querySelector('.ns-menu-open')!;
|
||||
const hamburger = navigation.querySelector(
|
||||
'[data-testid="nav-menu-toggle"]',
|
||||
)!;
|
||||
expect(
|
||||
open.compareDocumentPosition(hamburger) & FOLLOWING,
|
||||
).toBeTruthy();
|
||||
const panel = navigation.querySelector('#mobile-nav')!;
|
||||
const close = panel.querySelector('.ns-menu-close')!;
|
||||
const list = panel.querySelector('nav')!;
|
||||
expect(list.contains(close)).toBe(false);
|
||||
expect(close.compareDocumentPosition(list) & FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
it('makes the light logo lazy except on the home page (BR-PRE-05)', async () => {
|
||||
const logos = async (path: string) =>
|
||||
parse(await serverHtml(<NavigationBar />, path)).querySelectorAll(
|
||||
'header img',
|
||||
);
|
||||
const inner = await logos('/over-mij');
|
||||
expect(inner[1]).toHaveAttribute('loading', 'lazy');
|
||||
expect(inner[0]).not.toHaveAttribute('loading');
|
||||
const home = await logos('/');
|
||||
expect(home[1]).not.toHaveAttribute('loading');
|
||||
expect(home[0]).not.toHaveAttribute('loading');
|
||||
});
|
||||
|
||||
it('hydrates without a mismatch with the noscript links in place', async () => {
|
||||
const { errors, container } = await hydratePage(<NavigationBar />);
|
||||
expect(errors).toEqual([]);
|
||||
expect(
|
||||
container.querySelector('[data-testid="nav-menu-toggle"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
|
||||
|
||||
// Menu links for a visitor without JavaScript. Plain elements: a browser with
|
||||
// scripting on ignores the noscript content, and the CSS in the head
|
||||
// (noScriptCss.ts) styles them.
|
||||
export function NoScriptMenuOpen() {
|
||||
return (
|
||||
<noscript>
|
||||
<a
|
||||
className="ns-menu-open"
|
||||
href={`#${MOBILE_NAV_ID}`}
|
||||
aria-label="Menu openen"
|
||||
data-testid="nav-noscript-open"
|
||||
>
|
||||
<span aria-hidden="true" />
|
||||
<span aria-hidden="true" />
|
||||
<span aria-hidden="true" />
|
||||
</a>
|
||||
</noscript>
|
||||
);
|
||||
}
|
||||
|
||||
export function NoScriptMenuClose() {
|
||||
return (
|
||||
<noscript>
|
||||
<a
|
||||
className="ns-menu-close"
|
||||
href={`#${HEADER_ID}`}
|
||||
data-testid="nav-noscript-close"
|
||||
>
|
||||
Menu sluiten
|
||||
</a>
|
||||
</noscript>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user