Announces manual hero slide changes and adds a pause button #5

Merged
Sluijsens merged 5 commits from fix/hero-carousel-announce-and-pause into master 2026-10-19 20:56:27 +02:00
7 changed files with 68 additions and 18 deletions
Showing only changes of commit b332f1a846 - Show all commits
@@ -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). - `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). - 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** **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. - *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. - *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); await page.mouse.move(0, 0);
const before = await slide(); const before = await slide();
await wait(7000); 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 pause.click();
await wait(300);
console.log('6a. na afspelen | live:', JSON.stringify(await live()));
await page.mouse.move(0, 0); await page.mouse.move(0, 0);
await wait(7000); await wait(7000);
console.log('6. hervat | slide nu:', await slide(), '| knoppen:', JSON.stringify(await buttons())); 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); await userEvent.click(pause);
expect(pause).toHaveAccessibleName('Diavoorstelling afspelen'); expect(pause).toHaveAccessibleName('Diavoorstelling afspelen');
expect(screen.getByTestId('hero-announcement')).toHaveTextContent(
'Diavoorstelling gepauzeerd',
);
expect(progress()).toHaveAttribute('data-state', 'paused'); expect(progress()).toHaveAttribute('data-state', 'paused');
// Blijft gepauzeerd als de muis de hero verlaat // Blijft gepauzeerd als de muis de hero verlaat
@@ -105,6 +108,9 @@ describe('Hero', () => {
await userEvent.click(pause); await userEvent.click(pause);
expect(pause).toHaveAccessibleName('Diavoorstelling pauzeren'); expect(pause).toHaveAccessibleName('Diavoorstelling pauzeren');
expect(screen.getByTestId('hero-announcement')).toHaveTextContent(
'Diavoorstelling speelt weer af',
);
expect(progress()).toHaveAttribute('data-state', 'running'); expect(progress()).toHaveAttribute('data-state', 'running');
expect(await axeResults(container)).toHaveNoViolations(); expect(await axeResults(container)).toHaveNoViolations();
}); });
+20 -6
View File
@@ -11,12 +11,25 @@ import LinkButton from '../LinkButton';
import HeroArrows from './HeroArrows'; import HeroArrows from './HeroArrows';
import HeroPauseButton from './HeroPauseButton'; import HeroPauseButton from './HeroPauseButton';
import HeroSocials from './HeroSocials'; import HeroSocials from './HeroSocials';
import useHeroSlider from './useHeroSlider'; import useHeroSlider, { type HeroAnnouncement } from './useHeroSlider';
import type { HeroContent, SocialLink } from '@/content/types'; import type { HeroContent, SocialLink } from '@/content/types';
import { slidesToLoad } from '@/lib/slidesToLoad'; import { slidesToLoad } from '@/lib/slidesToLoad';
const SLIDE_DURATION = '6s'; 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 = { type HeroProps = {
content: HeroContent; content: HeroContent;
socials: SocialLink[]; socials: SocialLink[];
@@ -26,7 +39,7 @@ export default function Hero({ content, socials }: HeroProps) {
const { title, tagline, cta, slides } = content; const { title, tagline, cta, slides } = content;
const { const {
active, active,
announce, announcement,
reducedMotion, reducedMotion,
autoplay, autoplay,
paused, paused,
@@ -152,7 +165,7 @@ export default function Hero({ content, socials }: HeroProps) {
<HeroPauseButton stopped={stopped} onToggle={toggleStopped} /> <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 live-gebied moet al bestaan voordat de tekst verandert. Leeg na
een automatische wissel, zodat er geen oude melding blijft. */} een automatische wissel, zodat er geen oude melding blijft. */}
<VisuallyHidden <VisuallyHidden
@@ -160,9 +173,10 @@ export default function Hero({ content, socials }: HeroProps) {
aria-atomic="true" aria-atomic="true"
data-testid="hero-announcement" data-testid="hero-announcement"
> >
{announce {announcementText(
? `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}` announcement,
: ''} `Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`,
)}
</VisuallyHidden> </VisuallyHidden>
{/* Voortgangsbalk: als de animatie klaar is, schuift de slider door. {/* Voortgangsbalk: als de animatie klaar is, schuift de slider door.
+21 -4
View File
@@ -7,16 +7,33 @@ import useHeroSlider from './useHeroSlider';
describe('useHeroSlider', () => { describe('useHeroSlider', () => {
it('meldt een wissel door de bezoeker, een automatische niet', () => { it('meldt een wissel door de bezoeker, een automatische niet', () => {
const { result } = renderHook(() => useHeroSlider(8)); const { result } = renderHook(() => useHeroSlider(8));
expect(result.current.announce).toBe(false); expect(result.current.announcement).toBeNull();
act(() => result.current.next()); act(() => result.current.next());
expect(result.current).toMatchObject({ active: 1, announce: true }); expect(result.current).toMatchObject({
active: 1,
announcement: 'slide',
});
act(() => result.current.advance()); act(() => result.current.advance());
expect(result.current).toMatchObject({ active: 2, announce: false }); expect(result.current).toMatchObject({ active: 2, announcement: null });
act(() => result.current.prev()); 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', () => { 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 // 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 // gebeurt via de animatie van de voortgangsbalk (zie Hero.tsx), zodat pauzeren
// simpelweg die animatie stilzet. // simpelweg die animatie stilzet.
// Een wissel door de bezoeker (pijl, swipe) wordt gemeld aan schermlezers; // Wat de bezoeker zelf doet (pijl, swipe, pauzeknop) wordt gemeld aan
// een automatische wissel niet, anders onderbreekt hij elke paar seconden. // 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) { export default function useHeroSlider(count: number) {
const [index, setIndex] = useState(0); 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) // Pauzeknop: blijft gelden tot de bezoeker opnieuw klikt (WCAG 2.2.2)
const [stopped, setStopped] = useState(false); const [stopped, setStopped] = useState(false);
const [hovered, setHovered] = useState(false); const [hovered, setHovered] = useState(false);
@@ -40,15 +44,14 @@ export default function useHeroSlider(count: number) {
const go = (to: number, visitor: boolean) => { const go = (to: number, visitor: boolean) => {
setIndex((to + count) % count); setIndex((to + count) % count);
setByVisitor(visitor); setAnnouncement(visitor ? 'slide' : null);
}; };
const next = () => go(active + 1, true); const next = () => go(active + 1, true);
const prev = () => go(active - 1, true); const prev = () => go(active - 1, true);
return { return {
active, active,
// Alleen na een wissel door de bezoeker iets te melden announcement,
announce: byVisitor,
reducedMotion, reducedMotion,
autoplay: count > 1 && !reducedMotion, autoplay: count > 1 && !reducedMotion,
paused: stopped || hovered || focused || hidden, paused: stopped || hovered || focused || hidden,
@@ -62,6 +65,7 @@ export default function useHeroSlider(count: number) {
setFocused(false); setFocused(false);
} }
setStopped(!stopped); setStopped(!stopped);
setAnnouncement(stopped ? 'playing' : 'paused');
}, },
next, next,
prev, prev,
+1 -1
View File
@@ -21,7 +21,7 @@ const heroContent: HeroContent = {
{ {
id: 'hero-1', id: 'hero-1',
src: hero1, src: hero1,
alt: 'Lifestyle fotografie van Andrea Slop', alt: 'Lifestyle fotografie',
}, },
{ {
id: 'hero-2', id: 'hero-2',