diff --git a/aidlc-docs/active-features.md b/aidlc-docs/active-features.md index 60537e8..490ca3d 100644 --- a/aidlc-docs/active-features.md +++ b/aidlc-docs/active-features.md @@ -2,4 +2,5 @@ | Type | Name | Status | Branch | Affected Components | Session Start | |------|------|--------|--------|---------------------|---------------| +| Bug | [hero-carousel-announce-and-pause](bugs/hero-carousel-announce-and-pause/bug-fix.md) | ✅ Complete | fix/hero-carousel-announce-and-pause | web/src/components/Hero (Hero, HeroArrows, useHeroSlider) | 2026-10-19 | | Feature | frontend-shell | ✅ Complete | feature/frontend-shell | web/src (AppShell, NavigationBar, Footer, Hero socials, new BackToTop/SkipLink/404/error pages, routes, theme.ts, main.tsx), web/vite.config.js, web/package.json | 2026-10-14 | diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/bug-fix.md b/aidlc-docs/bugs/hero-carousel-announce-and-pause/bug-fix.md new file mode 100644 index 0000000..81d4e1f --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/bug-fix.md @@ -0,0 +1,103 @@ +# Bug Fix: Hero carousel gives no feedback on manual slide change and has no pause control + +- **Slug**: hero-carousel-announce-and-pause +- **Status**: Complete +- **Issue**: None (raised by the owner after the frontend-shell feature) +- **Branch**: fix/hero-carousel-announce-and-pause +- **Started**: 2026-10-19 +- **Documentation Language**: English (inherited from frontend-shell) +- **Conversation Language**: User Language (Dutch) + +## Report + +**Reproduction steps** +1. Open the home page (`https://test.andreaslop.nl/`) with a screen reader. +2. Activate "Volgende foto" (or "Vorige foto") in the hero. +3. Listen for what the screen reader says. +4. Look for a way to stop the automatic slide show. + +**Expected behaviour** +- A slide change **started by the visitor** (arrow buttons, swipe) is announced, e.g. "Foto 2 van 8: Zwangerschapsfoto in de duinen". +- An **automatic** slide change stays silent, otherwise the visitor is interrupted every 6 seconds. +- There is a visible button to pause and restart the automatic slide show (WCAG 2.2.2 Pause, Stop, Hide; the W3C APG carousel pattern calls this the rotation control). + +**Actual behaviour** +- After activating an arrow, the screen reader says nothing; the focus stays on the unchanged button. +- There is no pause control. Autoplay pauses only on mouse hover, keyboard focus inside the hero, a hidden tab, or `prefers-reduced-motion`. Touch users and screen reader users without keyboard focus in the hero cannot stop it. + +**Environment / context** +- Test environment, build `8f0f322` (master), Chrome headless 2026-10-19; applies to every browser and screen reader, as it is missing markup, not browser behaviour. +- Reproduction script: [hero-repro.mjs](hero-repro.mjs) (puppeteer), output: [repro-before.txt](repro-before.txt): + - live regions in the hero before and after a click: none + - active slide goes from "1 van 8" to "2 van 8" + - buttons in the accessibility tree: "Menu openen", "Vorige foto", "Volgende foto" (no pause control) + +## Root Cause + +**Confidence**: observed (reproduced on test and traced in code). + +1. **No announcement** — `web/src/components/Hero/Hero.tsx:51-90` renders each slide as `role="group"` with `aria-label="{n} van {total}"` and hides inactive slides with `aria-hidden`. That is correct structure, but nothing in the hero is an `aria-live` region. Screen readers only speak a DOM change that happens inside a live region, or content that receives focus. `HeroArrows.tsx:15-30` calls `prev`/`next` from `useHeroSlider.ts:36-37`, which only change `index`; focus stays on the arrow button, whose name does not change. So the change is silent. + - The manual/automatic distinction is also absent: `next` is the same function for the arrow (`HeroArrows`), the swipe handler (`useHeroSlider.ts:80-81`) and the end of the progress-bar animation (`Hero.tsx:151`). A live region that simply mirrors the active slide would therefore also speak every automatic change. +2. **No pause control** — `useHeroSlider.ts:39-44` derives `paused` only from `hovered`, `focused` (`:focus-visible` inside the hero) and `hidden`, and `autoplay` from `count > 1 && !reducedMotion`. There is no user-controlled state, and `Hero.tsx` renders no control for it. + +**Ruled out**: the slide `aria-label` and the image `alt` texts are present and correct; the problem is only that the change is not announced. The route-focus behaviour (`useRouteFocus`) is unrelated: it only acts on page navigation. + +**Confirmed with user**: 2026-10-19 — "A) Ja, zo bouwen. Je mag zelf bouwen, committed en pushen. Deploy naar test zodat ik zelf even kan testen, maar ga door in het proces tot de merge. Als ik heb getest en toestemming geef gaan we pas door" + +The pause button's place and look were proposed in the diagnosis and accepted with this answer: bottom right, mirroring the socials, same `iconControl` style, `pause-outlined` / `caret-right-outlined` icons, name switching between "Diavoorstelling pauzeren" and "Diavoorstelling afspelen". + +## The Fix + +**What changed** +- `web/src/components/Hero/useHeroSlider.ts` + - Slide changes go through one `go(to, visitor)`. `next`/`prev` (arrows, swipe) mark the change as made by the visitor; the new `advance` (end of the progress-bar animation) does not. `announce` exposes that flag. + - New `stopped` state with `toggleStopped`; `paused` now also includes `stopped`, so a manual pause survives the mouse leaving the hero. + - Resuming via the button also clears the hover and keyboard-focus pause. Without that, a click on "afspelen" did nothing visible: the click itself is a hover (and often a focus), which kept the slider paused. Found by the new test. +- `web/src/components/Hero/Hero.tsx` + - A `VisuallyHidden` live region (`aria-live="polite"`, `aria-atomic`) that is always rendered (a live region must exist before its text changes). It shows "Foto {n} van {total}: {alt}" after a visitor change and is empty after an automatic change, so no stale message remains. + - The progress bar calls `advance` instead of `next`, and carries `data-state="running|paused"`. + - Renders `HeroPauseButton` when autoplay is on. +- `web/src/components/Hero/HeroPauseButton.tsx` (new): the pause/play button, bottom right at the socials' height, `iconControl` recipe (44 px target, white focus ring). +- Tests: `Hero.test.tsx` (announcement, pause button, no button without autoplay, axe) and the new `useHeroSlider.test.tsx` (visitor vs. automatic change, wrap-around, resume clears hover and focus pause). + +**Follow-up after the owner's test (2026-10-19)**: "Nou is er eigenlijk hetzelfde probleem met de pauzeer-knop en de afspelen-knop. Zodra je erop klikt krijg je geen feedback dat de diavoorstelling is gepauzeerd. Verder vind ik de knop op een goede plek staan en er netjes uitzien." +- Same mechanism as the arrows: focus stays on the button and only its name changes; screen readers do not reliably read the new name of the focused button. +- `useHeroSlider.ts`: the boolean became `announcement: 'slide' | 'paused' | 'playing' | null`; `toggleStopped` sets `paused` or `playing`, `advance` still clears it. +- `Hero.tsx`: the same live region now also says "Diavoorstelling gepauzeerd" or "Diavoorstelling speelt weer af" (`announcementText`). +- Tests: the pause test checks both messages; the hook test checks them and that the next automatic change clears them. +- Placement and look of the button: approved by the owner. +- Commit `b332f1a` also carries an unrelated text change by the owner: the `alt` of `hero-1` in `web/src/content/heroContent.ts` went from "Lifestyle fotografie van Andrea Slop" to "Lifestyle fotografie" (picked up by `git add -A`; not in that commit's message). + +**Why this and not something else** +- *A live region that mirrors the active slide* (or toggling `aria-live` between `off` and `polite` as in the W3C example): it would speak automatic changes too, or depend on exactly when rotation is paused. Separating visitor and automatic changes in the hook states the intent directly. +- *Moving focus to the new slide*: would take the visitor away from the arrow they are pressing. +- *`aria-pressed` on the pause button*: the W3C carousel pattern changes the button's name instead; doing both makes screen readers say contradictory things. +- jsdom has no `AnimationEvent`, so React's `onAnimationEnd` cannot be triggered there; the automatic change is tested on the hook, and in a real browser by the script below. + +## Verification + +**Path used**: Automated test framework (Vitest + Testing Library + axe), plus the scripted browser check [hero-repro.mjs](hero-repro.mjs) for the real animation. + +**Before the fix** ([tests-before.txt](tests-before.txt), [repro-before.txt](repro-before.txt)) +- 3 of the new tests fail: no element `hero-announcement`, no `hero-progress` state, no button "Diavoorstelling pauzeren". +- Browser on test (`8f0f322`): no live region before or after a click; buttons: "Menu openen", "Vorige foto", "Volgende foto". + +**After the fix** +- Hero tests: 10 passed. Full suite: 118 tests in 23 files passed; lint, format, typecheck and build clean. +- Browser, local preview ([repro-after-local.txt](repro-after-local.txt)): + 1. before a click: live region present and empty + 2. after the arrow: "Foto 2 van 8: Knusse newbornfoto met de familie" + 3. after the automatic change to slide 3: live region empty + 4. buttons include "Diavoorstelling pauzeren" + 5. paused: slide stays at 3 for 7 s, button reads "Diavoorstelling afspelen" + 6. resumed: moves on to slide 4, button reads "Diavoorstelling pauzeren" again +- On test after the deploy (run 545, `46fb2f6`; check on the Pi, deploy on the Pi, Lighthouse on the PC, all green; PR run 544 green): the same six results as locally, see [repro-after-test.txt](repro-after-test.txt). +- Placement: [hero-desktop.png](hero-desktop.png) (1440×900) and [hero-mobile.png](hero-mobile.png) (390×844): the button sits bottom right, level with the socials and below the right arrow. +- Re-test on test after the pause announcements (run 547, `b332f1a`, all green): [repro-after-test.txt](repro-after-test.txt) adds "Diavoorstelling gepauzeerd" after pausing and "Diavoorstelling speelt weer af" after resuming. +- Owner's own screen reader check on test, 2026-10-19: the arrow announcement worked; the pause button gave no feedback on the first version (fixed in `b332f1a`); after that: "De knop doet nu wat ik verwacht en je hebt akkoord om te mergen en weer op te ruimen als er niks meer te doen is". + +## Result + +- **PR(s)**: #5 (https://gitea.slpsoftware.nl/SLP_Software/AndreaSlopFotografie/pulls/5) +- **Commit(s)**: 46fb2f6 (fix), b332f1a (pause announcements), e308aad and 45428e4 and this one (evidence) +- **Completed**: 2026-10-19 diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-desktop.png b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-desktop.png new file mode 100644 index 0000000..d7164bc Binary files /dev/null and b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-desktop.png differ diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-mobile.png b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-mobile.png new file mode 100644 index 0000000..07ef3fe Binary files /dev/null and b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-mobile.png differ diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-repro.mjs b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-repro.mjs new file mode 100644 index 0000000..cac2cf8 --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-repro.mjs @@ -0,0 +1,61 @@ +// Reproductie en verificatie (headless Chrome): meldt de Hero een wissel door +// de bezoeker, blijft hij stil bij een automatische wissel, en is er een +// pauzeknop die werkt? +// Gebruik: node hero-repro.mjs [url] +const { default: puppeteer } = await import(process.argv[2]); +const url = process.argv[3] ?? 'https://test.andreaslop.nl/'; +const wait = (ms) => new Promise((r) => setTimeout(r, ms)); +const browser = await puppeteer.launch({ + executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe', + headless: true, +}); +const page = await browser.newPage(); +await page.goto(url, { waitUntil: 'networkidle0' }); +// Muis buiten de hero, anders pauzeert hover de slider +await page.mouse.move(0, 0); + +const live = () => + page.$$eval('section[aria-roledescription="carousel"] [aria-live]', (els) => + els.map((e) => `${e.getAttribute('aria-live')}: "${e.textContent.trim()}"`), + ); +const slide = () => + page.$eval( + '[aria-roledescription="slide"]:not([aria-hidden="true"])', + (e) => e.getAttribute('aria-label'), + ); +const buttons = async () => { + const snap = await page.accessibility.snapshot({ interestingOnly: true }); + const names = []; + (function walk(n) { + if (n.role === 'button') names.push(n.name); + (n.children || []).forEach(walk); + })(snap); + return names; +}; + +console.log('1. voor klik | slide:', await slide(), '| live:', JSON.stringify(await live())); +await page.click('[data-testid="hero-next-button"]'); +await wait(500); +console.log('2. na pijlklik | slide:', await slide(), '| live:', JSON.stringify(await live())); +await page.mouse.move(0, 0); +await wait(7000); +console.log('3. na autoplay | slide:', await slide(), '| live:', JSON.stringify(await live())); +console.log('4. knoppen |', JSON.stringify(await buttons())); + +const pause = await page.$('[data-testid="hero-pause-button"]'); +if (pause) { + await pause.click(); + await page.mouse.move(0, 0); + const before = await slide(); + await wait(7000); + console.log('5. gepauzeerd | slide blijft:', before, '->', await slide(), '| live:', JSON.stringify(await live()), '| knoppen:', JSON.stringify(await buttons())); + await pause.click(); + await wait(300); + console.log('6a. na afspelen | live:', JSON.stringify(await live())); + await page.mouse.move(0, 0); + await wait(7000); + console.log('6. hervat | slide nu:', await slide(), '| knoppen:', JSON.stringify(await buttons())); +} else { + console.log('5. geen pauzeknop'); +} +await browser.close(); diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-local.txt b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-local.txt new file mode 100644 index 0000000..8942579 --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-local.txt @@ -0,0 +1,6 @@ +1. voor klik | slide: 1 van 8 | live: ["polite: \"\""] +2. na pijlklik | slide: 2 van 8 | live: ["polite: \"Foto 2 van 8: Knusse newbornfoto met de familie\""] +3. na autoplay | slide: 3 van 8 | live: ["polite: \"\""] +4. knoppen | ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling pauzeren"] +5. gepauzeerd | slide blijft: 3 van 8 -> 3 van 8 | knoppen: ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling afspelen"] +6. hervat | slide nu: 4 van 8 | knoppen: ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling pauzeren"] diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-test.txt b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-test.txt new file mode 100644 index 0000000..f0b8d7e --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-after-test.txt @@ -0,0 +1,7 @@ +1. voor klik | slide: 1 van 8 | live: ["polite: \"\""] +2. na pijlklik | slide: 2 van 8 | live: ["polite: \"Foto 2 van 8: Knusse newbornfoto met de familie\""] +3. na autoplay | slide: 3 van 8 | live: ["polite: \"\""] +4. knoppen | ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling pauzeren"] +5. gepauzeerd | slide blijft: 3 van 8 -> 3 van 8 | live: ["polite: \"Diavoorstelling gepauzeerd\""] | knoppen: ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling afspelen"] +6a. na afspelen | live: ["polite: \"Diavoorstelling speelt weer af\""] +6. hervat | slide nu: 4 van 8 | knoppen: ["Menu openen","Vorige foto","Volgende foto","Diavoorstelling pauzeren"] diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-before.txt b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-before.txt new file mode 100644 index 0000000..6e252c6 --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/repro-before.txt @@ -0,0 +1,5 @@ +live-gebieden voor klik: [] +actieve slide: 1 van 8 +actieve slide na klik: 2 van 8 +live-gebieden na klik: [] +knoppen in de toegankelijkheidsboom: ["Menu openen","Vorige foto","Volgende foto"] diff --git a/aidlc-docs/bugs/hero-carousel-announce-and-pause/tests-before.txt b/aidlc-docs/bugs/hero-carousel-announce-and-pause/tests-before.txt new file mode 100644 index 0000000..2291090 --- /dev/null +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/tests-before.txt @@ -0,0 +1,11 @@ + × meldt een wissel door de bezoeker met nummer en beschrijving 53ms + × blijft stil bij een automatische wissel 105ms + × pauzeert en hervat de diavoorstelling 81ms +⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯ + FAIL src/components/Hero/Hero.test.tsx > Hero > meldingen voor schermlezers > meldt een wissel door de bezoeker met nummer en beschrijving +TestingLibraryElementError: Unable to find an element by: [data-testid="hero-announcement"] + FAIL src/components/Hero/Hero.test.tsx > Hero > meldingen voor schermlezers > blijft stil bij een automatische wissel +TestingLibraryElementError: Unable to find an element by: [data-testid="hero-progress"] + FAIL src/components/Hero/Hero.test.tsx > Hero > pauzeknop > pauzeert en hervat de diavoorstelling +TestingLibraryElementError: Unable to find an accessible element with the role "button" and name "Diavoorstelling pauzeren" + Tests 3 failed | 4 passed (7) diff --git a/web/src/components/Hero/Hero.test.tsx b/web/src/components/Hero/Hero.test.tsx index d64b104..e19484f 100644 --- a/web/src/components/Hero/Hero.test.tsx +++ b/web/src/components/Hero/Hero.test.tsx @@ -53,6 +53,84 @@ describe('Hero', () => { expect(sources()).toEqual([slide(0), slide(1), slide(2)]); }); + describe('meldingen voor schermlezers', () => { + const announcement = () => + screen.getByTestId('hero-announcement').textContent; + + it('meldt een wissel door de bezoeker met nummer en beschrijving', async () => { + await renderWithProviders( + , + ); + const region = screen.getByTestId('hero-announcement'); + expect(region).toHaveAttribute('aria-live', 'polite'); + expect(announcement()).toBe(''); + + await userEvent.click( + screen.getByRole('button', { name: 'Volgende foto' }), + ); + expect(announcement()).toBe( + `Foto 2 van ${heroContent.slides.length}: ${heroContent.slides[1].alt}`, + ); + + await userEvent.click( + screen.getByRole('button', { name: 'Vorige foto' }), + ); + expect(announcement()).toBe( + `Foto 1 van ${heroContent.slides.length}: ${heroContent.slides[0].alt}`, + ); + }); + + // Stil blijven bij een automatische wissel: zie useHeroSlider.test.tsx + // (jsdom kent geen animationend voor React) + }); + + describe('pauzeknop', () => { + it('pauzeert en hervat de diavoorstelling', async () => { + const { container } = await renderWithProviders( + , + ); + const pause = screen.getByRole('button', { + name: 'Diavoorstelling pauzeren', + }); + const progress = () => screen.getByTestId('hero-progress'); + expect(progress()).toHaveAttribute('data-state', 'running'); + + await userEvent.click(pause); + expect(pause).toHaveAccessibleName('Diavoorstelling afspelen'); + expect(screen.getByTestId('hero-announcement')).toHaveTextContent( + 'Diavoorstelling gepauzeerd', + ); + expect(progress()).toHaveAttribute('data-state', 'paused'); + + // Blijft gepauzeerd als de muis de hero verlaat + fireEvent.pointerLeave(container.querySelector('section')!); + expect(progress()).toHaveAttribute('data-state', 'paused'); + + await userEvent.click(pause); + expect(pause).toHaveAccessibleName('Diavoorstelling pauzeren'); + expect(screen.getByTestId('hero-announcement')).toHaveTextContent( + 'Diavoorstelling speelt weer af', + ); + expect(progress()).toHaveAttribute('data-state', 'running'); + expect(await axeResults(container)).toHaveNoViolations(); + }); + + it('ontbreekt als er niets automatisch wisselt', async () => { + await renderWithProviders( + , + ); + expect( + screen.queryByRole('button', { name: /Diavoorstelling/ }), + ).not.toBeInTheDocument(); + }); + }); + it('heeft pijlen met een toegankelijke naam', async () => { await renderWithProviders( , diff --git a/web/src/components/Hero/Hero.tsx b/web/src/components/Hero/Hero.tsx index 922338d..62b9d99 100644 --- a/web/src/components/Hero/Hero.tsx +++ b/web/src/components/Hero/Hero.tsx @@ -1,14 +1,35 @@ import { useState } from 'react'; -import { Box, chakra, Container, Heading, Image } from '@chakra-ui/react'; +import { + Box, + chakra, + Container, + Heading, + Image, + VisuallyHidden, +} from '@chakra-ui/react'; import LinkButton from '../LinkButton'; import HeroArrows from './HeroArrows'; +import HeroPauseButton from './HeroPauseButton'; import HeroSocials from './HeroSocials'; -import useHeroSlider from './useHeroSlider'; +import useHeroSlider, { type HeroAnnouncement } from './useHeroSlider'; import type { HeroContent, SocialLink } from '@/content/types'; import { slidesToLoad } from '@/lib/slidesToLoad'; const SLIDE_DURATION = '6s'; +function announcementText(announcement: HeroAnnouncement, slide: string) { + switch (announcement) { + case 'slide': + return slide; + case 'paused': + return 'Diavoorstelling gepauzeerd'; + case 'playing': + return 'Diavoorstelling speelt weer af'; + default: + return ''; + } +} + type HeroProps = { content: HeroContent; socials: SocialLink[]; @@ -16,8 +37,19 @@ type HeroProps = { export default function Hero({ content, socials }: HeroProps) { const { title, tagline, cta, slides } = content; - const { active, reducedMotion, autoplay, paused, next, prev, handlers } = - useHeroSlider(slides.length); + const { + active, + announcement, + reducedMotion, + autoplay, + paused, + stopped, + toggleStopped, + next, + prev, + advance, + handlers, + } = useHeroSlider(slides.length); // De slides liggen op elkaar in beeld, dus loading="lazy" stelt niets uit. // Eerst alleen de actieve foto; zodra die binnen en getekend is (twee // frames later, dus na de eerste paint) ook de volgende en de vorige. @@ -129,6 +161,23 @@ export default function Hero({ content, socials }: HeroProps) { {slides.length > 1 && } + {autoplay && ( + + )} + + {/* Meldt een wissel of pauze door de bezoeker; staat er altijd, want een + live-gebied moet al bestaan voordat de tekst verandert. Leeg na + een automatische wissel, zodat er geen oude melding blijft. */} + + {announcementText( + announcement, + `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`, + )} + {/* Voortgangsbalk: als de animatie klaar is, schuift de slider door. Door de key start hij opnieuw bij elke slidewissel. */} @@ -136,6 +185,8 @@ export default function Hero({ content, socials }: HeroProps) { )} diff --git a/web/src/components/Hero/HeroPauseButton.tsx b/web/src/components/Hero/HeroPauseButton.tsx new file mode 100644 index 0000000..bb248ee --- /dev/null +++ b/web/src/components/Hero/HeroPauseButton.tsx @@ -0,0 +1,42 @@ +import { chakra, useRecipe } from '@chakra-ui/react'; +import { Icon } from '@iconify/react/offline'; +import caretRightOutlined from '@iconify-icons/ant-design/caret-right-outlined'; +import pauseOutlined from '@iconify-icons/ant-design/pause-outlined'; + +type HeroPauseButtonProps = { + stopped: boolean; + onToggle: () => void; +}; + +// Rechtsonder, spiegelbeeld van de socials linksonder. De naam wisselt mee +// met de stand (W3C carrouselpatroon), daarom geen aria-pressed. +export default function HeroPauseButton({ + stopped, + onToggle, +}: HeroPauseButtonProps) { + const iconControl = useRecipe({ key: 'iconControl' }); + + return ( + + + + ); +} diff --git a/web/src/components/Hero/useHeroSlider.test.tsx b/web/src/components/Hero/useHeroSlider.test.tsx new file mode 100644 index 0000000..50830ff --- /dev/null +++ b/web/src/components/Hero/useHeroSlider.test.tsx @@ -0,0 +1,86 @@ +import { act, fireEvent, render, renderHook } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import useHeroSlider from './useHeroSlider'; + +// De automatische wissel komt in de browser van animationend op de +// voortgangsbalk; jsdom kent geen AnimationEvent, dus hier rechtstreeks. +describe('useHeroSlider', () => { + it('meldt een wissel door de bezoeker, een automatische niet', () => { + const { result } = renderHook(() => useHeroSlider(8)); + expect(result.current.announcement).toBeNull(); + + act(() => result.current.next()); + expect(result.current).toMatchObject({ + active: 1, + announcement: 'slide', + }); + + act(() => result.current.advance()); + expect(result.current).toMatchObject({ active: 2, announcement: null }); + + act(() => result.current.prev()); + expect(result.current).toMatchObject({ + active: 1, + announcement: 'slide', + }); + }); + + it('meldt pauzeren en afspelen via de knop', () => { + const { result } = renderHook(() => useHeroSlider(8)); + act(() => result.current.toggleStopped()); + expect(result.current.announcement).toBe('paused'); + act(() => result.current.toggleStopped()); + expect(result.current.announcement).toBe('playing'); + // De volgende automatische wissel maakt de melding weer leeg + act(() => result.current.advance()); + expect(result.current.announcement).toBeNull(); + }); + + it('loopt rond aan beide kanten', () => { + const { result } = renderHook(() => useHeroSlider(3)); + act(() => result.current.prev()); + expect(result.current.active).toBe(2); + act(() => result.current.advance()); + expect(result.current.active).toBe(0); + }); + + it('afspelen via de knop heft ook de pauze door hover op', () => { + let slider!: ReturnType; + function Probe() { + slider = useHeroSlider(8); + return
; + } + const { getByTestId } = render(); + fireEvent.pointerEnter(getByTestId('hero'), { pointerType: 'mouse' }); + expect(slider.paused).toBe(true); + + act(() => slider.toggleStopped()); + act(() => slider.toggleStopped()); + expect(slider.paused).toBe(false); + }); + + it('afspelen via de knop heft ook de pauze door toetsenbordfocus op', () => { + let slider!: ReturnType; + function Probe() { + slider = useHeroSlider(8); + return ( +
+ +
+ ); + } + const { getByRole } = render(); + const button = getByRole('button'); + // :focus-visible bestaat niet in jsdom; doe alsof het toetsenbordfocus is + vi.spyOn(button, 'matches').mockReturnValue(true); + + fireEvent.focus(button); + expect(slider.paused).toBe(true); + + act(() => slider.toggleStopped()); + expect(slider).toMatchObject({ stopped: true, paused: true }); + + act(() => slider.toggleStopped()); + expect(slider).toMatchObject({ stopped: false, paused: false }); + }); +}); diff --git a/web/src/components/Hero/useHeroSlider.ts b/web/src/components/Hero/useHeroSlider.ts index 779bf19..bac7f6f 100644 --- a/web/src/components/Hero/useHeroSlider.ts +++ b/web/src/components/Hero/useHeroSlider.ts @@ -7,8 +7,17 @@ const SWIPE_THRESHOLD = 50; // Houdt de actieve slide bij en of autoplay mag lopen. Het doorschuiven zelf // gebeurt via de animatie van de voortgangsbalk (zie Hero.tsx), zodat pauzeren // simpelweg die animatie stilzet. +// Wat de bezoeker zelf doet (pijl, swipe, pauzeknop) wordt gemeld aan +// schermlezers; een automatische wissel niet, anders onderbreekt hij elke paar +// seconden. De naam van de pauzeknop wisselt wel mee, maar een schermlezer +// leest een nieuwe naam van de knop met focus niet altijd voor. +export type HeroAnnouncement = 'slide' | 'paused' | 'playing' | null; + export default function useHeroSlider(count: number) { const [index, setIndex] = useState(0); + const [announcement, setAnnouncement] = useState(null); + // Pauzeknop: blijft gelden tot de bezoeker opnieuw klikt (WCAG 2.2.2) + const [stopped, setStopped] = useState(false); const [hovered, setHovered] = useState(false); const [focused, setFocused] = useState(false); const [hidden, setHidden] = useState(() => document.hidden); @@ -33,16 +42,34 @@ export default function useHeroSlider(count: number) { // Als de API minder slides teruggeeft dan de huidige index, begin vooraan. const active = index < count ? index : 0; - const next = () => setIndex((active + 1) % count); - const prev = () => setIndex((active - 1 + count) % count); + const go = (to: number, visitor: boolean) => { + setIndex((to + count) % count); + setAnnouncement(visitor ? 'slide' : null); + }; + const next = () => go(active + 1, true); + const prev = () => go(active - 1, true); return { active, + announcement, reducedMotion, autoplay: count > 1 && !reducedMotion, - paused: hovered || focused || hidden, + paused: stopped || hovered || focused || hidden, + stopped, + // Afspelen via de knop geldt ook terwijl de muis of de + // toetsenbordfocus nog in de hero staat (de klik zelf is een hover en + // vaak een focus); zonder dit gebeurt er na "afspelen" niets zichtbaars. + toggleStopped: () => { + if (stopped) { + setHovered(false); + setFocused(false); + } + setStopped(!stopped); + setAnnouncement(stopped ? 'playing' : 'paused'); + }, next, prev, + advance: () => go(active + 1, false), handlers: { // Alleen een echte muis pauzeert; een tik op mobiel niet. onPointerEnter: (event: React.PointerEvent) => { diff --git a/web/src/content/heroContent.ts b/web/src/content/heroContent.ts index e4730e2..51d5d1a 100644 --- a/web/src/content/heroContent.ts +++ b/web/src/content/heroContent.ts @@ -21,7 +21,7 @@ const heroContent: HeroContent = { { id: 'hero-1', src: hero1, - alt: 'Lifestyle fotografie van Andrea Slop', + alt: 'Lifestyle fotografie', }, { id: 'hero-2',