Autoplay a Carousel with Pause
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Make a carousel play on its own. Props: slides, a list of { title, text } objects (the starter has four), and interval, in milliseconds (default 3000). Show only the current slide's title, in an h3 heading (leave the others out, or hide them with the hidden attribute), and a line like "Slide 2 of 4". Every interval milliseconds the carousel moves to the next slide, wrapping from the last back to the first. A button reads "Pause" while it plays; clicking it stops the slides where they are, and the button then reads "Play". Clicking Play starts them again, waiting a full interval before the next move. So screen readers aren't interrupted every few seconds, put aria-live on an element that holds both the heading and the "Slide 2 of 4" line: "off" while playing and "polite" while paused. Stop the timer when paused and when the component unmounts. The checks use intervals of a few hundred milliseconds or less.
Your code must pass
- Moves to the next slide every interval, wrapping round
- Waits the full interval before moving
- Pause stops the slides, and the button then reads "Play"
- Play starts the slides again
- The slide area is aria-live "off" while playing and "polite" when paused