Carousel
A slideshow component for cycling through content with auto-play, swipe gestures, and navigation controls.
Import
Usage
Examples
Variant
Size
Radius
Auto-play
Loop
With controls
With indicators
Pause on hover
Without animation
Controlled
Current slide: 1
Custom controls
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | CarouselItem[] | None | Array of slides to render |
children | ReactNode | None | Alternative to items prop for simple usage |
variant | "bordered" | "ghost" | "bordered"* | Visual style of the carousel |
size | "sm" | "md" | "lg" | "md" | Size scale for height and padding |
radius | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "full" | "lg"* | Corner rounding |
autoPlay | boolean | false* | Automatically advance slides |
autoPlayInterval | number | 5000* | Delay in ms between auto-play transitions |
loop | boolean | true* | Enable infinite looping |
showControls | boolean | true* | Show navigation arrows |
showIndicators | boolean | true* | Show dot indicators |
pauseOnHover | boolean | true* | Pause auto-play when hovered |
disableAnimation | boolean | false | Disable slide transition animations |
defaultIndex | number | 0 | Initial slide index for uncontrolled usage |
index | number | None | Controlled slide index |
onIndexChange | (index: number) => void | None | Callback when slide changes |
renderPrevControl | (props: { onClick: () => void; disabled: boolean }) => ReactNode | None | Custom previous control renderer |
renderNextControl | (props: { onClick: () => void; disabled: boolean }) => ReactNode | None | Custom next control renderer |
itemClassName | string | None | Extra classes applied to each slide |
controlClassName | string | None | Extra classes for control buttons |
indicatorClassName | string | None | Extra classes for indicator dots |
className | string | None | Extra classes, merged with internal styles |
* Falls back through Global Configuration if not set. See below.
CarouselItem
| Prop | Type | Description |
|---|---|---|
id | string | Unique identifier for the slide |
content | ReactNode | Slide content |
Global Configuration
Carousel reads defaults from four places, in this order of precedence:
- Instance prop: set directly on
<Carousel /> - Component config:
components.carouselin yourashee.config - Theme default:
defaultVariant/defaultRadiusin yourashee.config - Built-in fallback: component's internal default values
Component config
Built-in fallbacks
Accessibility
- Uses native button elements for controls with proper
aria-labelattributes - Supports keyboard navigation via focus management
- Dot indicators include
aria-labelwith slide number - Touch gestures support pointer events
- Disabled controls prevent interaction in non-looping carousels
- Implements
focus-visiblerings for keyboard navigation
Notes
- Items vs Children: Use
itemsfor structured data orchildrenfor simple content. If both are provided,itemstakes precedence. - Controlled vs Uncontrolled: Use
index/onIndexChangefor controlled usage, ordefaultIndexfor uncontrolled. - Swipe Support: The carousel supports touch and mouse drag gestures with a 50px threshold for swipe detection.
- Auto-play: Auto-play pauses when the carousel is hovered (if
pauseOnHoveris enabled) or when dragging. - Looping: When
loopisfalse, navigation controls are disabled at the first and last slides. - Performance: For large carousels with many slides, consider using
disableAnimationto reduce layout shifts.