Carousel
An accessible carousel component with auto-play, keyboard navigation, and pause on hover/focus. Respects reduced motion preferences and provides proper ARIA markup.
Basic Usage
Navigate slides using controls, indicators, or keyboard. Auto-play pauses on hover/focus.
import { AccessibleCarousel } from '@a13y/react';
const slides = [
<div key="1" className="h-64 bg-blue-500 flex items-center justify-center">
<h2 className="text-white text-2xl">Slide 1</h2>
</div>,
<div key="2" className="h-64 bg-green-500 flex items-center justify-center">
<h2 className="text-white text-2xl">Slide 2</h2>
</div>,
<div key="3" className="h-64 bg-purple-500 flex items-center justify-center">
<h2 className="text-white text-2xl">Slide 3</h2>
</div>
];
function Example() {
return (
<AccessibleCarousel
items={slides}
autoPlay
interval={5000}
controls
indicators
/>
);
}Manual Navigation
Carousel with auto-play disabled for manual control.
Props
| Name | Type | Default | Description |
|---|---|---|---|
items* | ReactNode[] | - | Array of carousel slide content |
autoPlay | boolean | false | Enable automatic slide rotation |
interval | number | 5000 | Time in milliseconds between auto-rotation |
controls | boolean | true | Show previous/next navigation controls |
indicators | boolean | true | Show slide position indicators |
loop | boolean | true | Loop back to first/last slide at edges |
ariaLabel | string | 'Carousel' | Accessible label for the carousel |
className | string | - | Optional CSS class |
Keyboard Navigation
←Previous slide
→Next slide
HomeFirst slide
EndLast slide
Accessibility Features
- ✓Uses
sectionwitharia-roledescription="carousel" - ✓Each slide marked with
role="group"andaria-roledescription="slide" - ✓Auto-play pauses on hover and focus
- ✓Play/pause button with clear labels
- ✓Respects prefers-reduced-motion for animations
- ✓Screen reader announcements for slide changes