From b332f1a84672f14667fc7a863cc9aebe612b433e Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 19 Oct 2026 20:33:47 +0200 Subject: [PATCH] Announces pausing and resuming the hero slide show The pause button only changed its name, which screen readers often do not read for the focused button. The live region now also says when the slide show is paused or plays again. Co-Authored-By: Claude Opus 5.5 --- .../bug-fix.md | 7 +++++ .../hero-repro.mjs | 4 ++- web/src/components/Hero/Hero.test.tsx | 6 +++++ web/src/components/Hero/Hero.tsx | 26 ++++++++++++++----- .../components/Hero/useHeroSlider.test.tsx | 25 +++++++++++++++--- web/src/components/Hero/useHeroSlider.ts | 16 +++++++----- web/src/content/heroContent.ts | 2 +- 7 files changed, 68 insertions(+), 18 deletions(-) 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 index dc7fca9..d44bd64 100644 --- a/aidlc-docs/bugs/hero-carousel-announce-and-pause/bug-fix.md +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/bug-fix.md @@ -60,6 +60,13 @@ The pause button's place and look were proposed in the diagnosis and accepted wi - `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. + **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. 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 index 6e57db5..cac2cf8 100644 --- a/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-repro.mjs +++ b/aidlc-docs/bugs/hero-carousel-announce-and-pause/hero-repro.mjs @@ -48,8 +48,10 @@ if (pause) { await page.mouse.move(0, 0); const before = await slide(); await wait(7000); - console.log('5. gepauzeerd | slide blijft:', before, '->', await slide(), '| knoppen:', JSON.stringify(await buttons())); + 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())); diff --git a/web/src/components/Hero/Hero.test.tsx b/web/src/components/Hero/Hero.test.tsx index e65187b..e19484f 100644 --- a/web/src/components/Hero/Hero.test.tsx +++ b/web/src/components/Hero/Hero.test.tsx @@ -97,6 +97,9 @@ describe('Hero', () => { 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 @@ -105,6 +108,9 @@ describe('Hero', () => { 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(); }); diff --git a/web/src/components/Hero/Hero.tsx b/web/src/components/Hero/Hero.tsx index aa5255d..62b9d99 100644 --- a/web/src/components/Hero/Hero.tsx +++ b/web/src/components/Hero/Hero.tsx @@ -11,12 +11,25 @@ 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[]; @@ -26,7 +39,7 @@ export default function Hero({ content, socials }: HeroProps) { const { title, tagline, cta, slides } = content; const { active, - announce, + announcement, reducedMotion, autoplay, paused, @@ -152,7 +165,7 @@ export default function Hero({ content, socials }: HeroProps) { )} - {/* Meldt een wissel door de bezoeker; staat er altijd, want een + {/* 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. */} - {announce - ? `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}` - : ''} + {announcementText( + announcement, + `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`, + )} {/* Voortgangsbalk: als de animatie klaar is, schuift de slider door. diff --git a/web/src/components/Hero/useHeroSlider.test.tsx b/web/src/components/Hero/useHeroSlider.test.tsx index 3627638..50830ff 100644 --- a/web/src/components/Hero/useHeroSlider.test.tsx +++ b/web/src/components/Hero/useHeroSlider.test.tsx @@ -7,16 +7,33 @@ import useHeroSlider from './useHeroSlider'; describe('useHeroSlider', () => { it('meldt een wissel door de bezoeker, een automatische niet', () => { const { result } = renderHook(() => useHeroSlider(8)); - expect(result.current.announce).toBe(false); + expect(result.current.announcement).toBeNull(); act(() => result.current.next()); - expect(result.current).toMatchObject({ active: 1, announce: true }); + expect(result.current).toMatchObject({ + active: 1, + announcement: 'slide', + }); act(() => result.current.advance()); - expect(result.current).toMatchObject({ active: 2, announce: false }); + expect(result.current).toMatchObject({ active: 2, announcement: null }); act(() => result.current.prev()); - expect(result.current).toMatchObject({ active: 1, announce: true }); + 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', () => { diff --git a/web/src/components/Hero/useHeroSlider.ts b/web/src/components/Hero/useHeroSlider.ts index b2e9a33..bac7f6f 100644 --- a/web/src/components/Hero/useHeroSlider.ts +++ b/web/src/components/Hero/useHeroSlider.ts @@ -7,11 +7,15 @@ 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. -// Een wissel door de bezoeker (pijl, swipe) wordt gemeld aan schermlezers; -// een automatische wissel niet, anders onderbreekt hij elke paar seconden. +// 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 [byVisitor, setByVisitor] = useState(false); + 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); @@ -40,15 +44,14 @@ export default function useHeroSlider(count: number) { const go = (to: number, visitor: boolean) => { setIndex((to + count) % count); - setByVisitor(visitor); + setAnnouncement(visitor ? 'slide' : null); }; const next = () => go(active + 1, true); const prev = () => go(active - 1, true); return { active, - // Alleen na een wissel door de bezoeker iets te melden - announce: byVisitor, + announcement, reducedMotion, autoplay: count > 1 && !reducedMotion, paused: stopped || hovered || focused || hidden, @@ -62,6 +65,7 @@ export default function useHeroSlider(count: number) { setFocused(false); } setStopped(!stopped); + setAnnouncement(stopped ? 'playing' : 'paused'); }, next, prev, 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',