Overview
Modern web applications heavily rely on engaging and intuitive user interfaces. An image carousel is a fundamental component for showcasing product images, portfolios, or news highlights. A well-implemented carousel not only looks good but also provides a seamless and accessible experience for all users, enhancing content discoverability and user interaction. This problem challenges you to build a robust, accessible, and performant image carousel component.
What you need to do / Task
You are tasked with building a reusable ImageCarousel React component that displays a collection of images and provides various navigation and interaction features.
- Display Images: Render a list of images provided as props.
- Navigation Controls: Implement 'Previous' and 'Next' buttons to cycle through images.
- Dot Indicators: Display a set of clickable dot indicators, one for each image, to allow direct navigation.
- Infinite Looping: The carousel should loop infinitely, meaning navigating 'Next' from the last image goes to the first, and 'Previous' from the first goes to the last.
- Keyboard Navigation: Enable navigation using the Left and Right arrow keys.
- Autoplay: Implement an autoplay feature that automatically advances the carousel every few seconds.
- Pause on Interaction: The autoplay should pause when the user hovers over the carousel or when any interactive element within the carousel gains focus. Autoplay should resume when the user moves the mouse off or focus is lost.
- Accessibility: Ensure the component is highly accessible, adhering to WAI-ARIA guidelines for carousels.
- Responsiveness: The carousel should adapt gracefully to different screen sizes.
UI/UX expectations
- The currently active image should be clearly visible.
- Navigation buttons (Previous/Next) should be present on the sides of the carousel.
- Dot indicators should be positioned typically below the images, with the active dot visually distinct.
- When autoplay is paused due to user interaction, there should be no visual indicator for play/pause, it should just stop advancing.
- Focus outlines should be visible for interactive elements (buttons, dots).
- The carousel should take up a reasonable width and height, adapting to its container.
Acceptance criteria
- The
ImageCarousel component renders correctly with provided image data.
- 'Previous' and 'Next' buttons correctly change the displayed image.
- Clicking a dot indicator navigates to the corresponding image.
- Navigating 'Next' from the last image displays the first image, and 'Previous' from the first displays the last.
- Left arrow key navigates to the previous image, and Right arrow key navigates to the next image.
- Autoplay automatically transitions images after a fixed delay (e.g., 3-5 seconds).
- Autoplay pauses when the mouse pointer is over the carousel container or any interactive element within it is focused.
- Autoplay resumes when the mouse leaves the carousel or focus shifts away.
- The carousel element has
role="region" and aria-label="Image Carousel" (or similar).
- Each image within the carousel has appropriate
alt text.
- Navigation buttons and dot indicators have clear
aria-label attributes.
- The currently visible image is indicated with
aria-current="true" or similar accessible state.
- The carousel layout adjusts reasonably well on smaller screens (e.g., images scale, controls remain accessible).