Overview
Modern e-commerce platforms and content-rich websites heavily rely on compelling visual experiences. An image carousel is a fundamental component for showcasing multiple product angles, portfolio items, or news galleries efficiently. For an L5 role, building such a component goes beyond basic functionality, demanding attention to performance, accessibility, and robust interaction design.
This problem challenges you to develop a sophisticated image carousel that not only works seamlessly but also provides an inclusive and performant experience, mirroring the quality expected in a production-grade application.
What you need to do / Task
Your goal is to build a Carousel component that displays a series of images with advanced features:
- Main Image Display: Show a single large image at a time.
- Navigation Controls: Implement 'Previous' and 'Next' buttons to cycle through images.
- Thumbnail Navigation: Display a row of smaller image thumbnails. Clicking a thumbnail should navigate to the corresponding main image.
- Infinite Looping: The carousel should seamlessly loop from the last image to the first, and vice-versa, without showing explicit start/end states.
- Auto-play with Interaction Pause: The carousel should automatically advance to the next image every 3 seconds. This auto-play should pause when the user hovers their mouse over the carousel or when any part of the carousel receives keyboard focus. Auto-play should resume when the user moves their mouse away or focus is lost.
- Accessibility (Keyboard Navigation):
- Users should be able to navigate between images using the Left/Right arrow keys when the carousel component or any of its children are focused.
- The 'Previous', 'Next', and thumbnail controls should be tabbable and operable via Enter/Space keys.
- Appropriate ARIA attributes (e.g.,
aria-live, aria-roledescription, aria-label, aria-current) should be used to convey the carousel's state and controls' purpose to assistive technologies.
- Performance (Lazy Loading): Implement lazy loading for images that are not currently visible in the main display or in the immediate vicinity of the viewport (e.g., only load the current, previous, and next images fully, and only load thumbnails when they become visible or are clicked).
UI/UX expectations
- The main image should be prominently displayed, with navigation buttons clearly visible on its sides or below.
- Thumbnails should be arranged horizontally below the main image, with the currently active thumbnail visually highlighted.
- The carousel should be reasonably responsive, adapting its layout for different screen sizes (e.g., ensuring controls remain accessible).
- Transitions between images can be instantaneous or use a simple CSS transition for smoothness.
- Focus indicators for interactive elements (buttons, thumbnails) should be clear.
Acceptance criteria
- The carousel correctly displays images from the provided data.
- 'Previous' and 'Next' buttons navigate through images, wrapping infinitely.
- Clicking a thumbnail updates the main image and highlights the active thumbnail.
- Auto-play automatically advances images and correctly pauses/resumes on hover/focus.
- Left/Right arrow keys navigate images when the carousel is focused.
- All interactive elements are keyboard tabbable and operable.
- Screen readers announce carousel state and interaction options correctly using ARIA attributes.
- Images not immediately visible are lazy-loaded, improving initial page load performance.
- The component maintains a functional and visually coherent layout across common screen sizes (responsive).