Announces pausing and resuming the hero slide show
Continuous Integration / check (pull_request) Successful in 6m47s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 3m47s
Continuous Integration / deploy-production (pull_request) Skipped

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 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 20:33:47 +02:00
co-authored by Claude Opus 5.5
parent e308aad8f0
commit b332f1a846
7 changed files with 68 additions and 18 deletions
@@ -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.
@@ -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()));
+6
View File
@@ -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();
});
+20 -6
View File
@@ -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) {
<HeroPauseButton stopped={stopped} onToggle={toggleStopped} />
)}
{/* 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. */}
<VisuallyHidden
@@ -160,9 +173,10 @@ export default function Hero({ content, socials }: HeroProps) {
aria-atomic="true"
data-testid="hero-announcement"
>
{announce
? `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`
: ''}
{announcementText(
announcement,
`Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`,
)}
</VisuallyHidden>
{/* Voortgangsbalk: als de animatie klaar is, schuift de slider door.
+21 -4
View File
@@ -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', () => {
+10 -6
View File
@@ -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<HeroAnnouncement>(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,
+1 -1
View File
@@ -21,7 +21,7 @@ const heroContent: HeroContent = {
{
id: 'hero-1',
src: hero1,
alt: 'Lifestyle fotografie van Andrea Slop',
alt: 'Lifestyle fotografie',
},
{
id: 'hero-2',