Carousel
Each child is a slide. Controlled via index + onIndexChange or uncontrolled via defaultIndex. autoPlay (ms) pauses on hover and focus; loop={false} stops at the ends. Arrow keys work while it has focus. The previous and next buttons are icon buttons with tooltips, centred on the slides; the dots below jump to a slide.
Slides can be anything: here each one is an Image with a caption laid over it.
The wording of the buttons can be changed, for example to match what the slides are or to translate it: previousLabel, nextLabel and dotLabel(index). The first two are used for both the aria-label and the tooltip.
Props
childrenReactNodeOne child per slide.
indexnumberCurrent slide (controlled).
defaultIndexnumberDefault:0Initial slide (uncontrolled).
onIndexChange(index: number) => voidCalled when the slide changes.
autoPlaynumberDefault:0Auto-advance interval in ms (0 = off); pauses on hover and focus.
loopbooleanDefault:trueWrap around at the ends.
labelstringDefault:'Carousel'Accessible name.
previousLabelstringDefault:'Previous slide'Wording of the previous button (aria-label and tooltip).
nextLabelstringDefault:'Next slide'Wording of the next button (aria-label and tooltip).
dotLabel(index: number) => stringDefault:(i) => `Go to slide ${i + 1}`Aria-label of the dot for slide
index(0-based).classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | One child per slide. |
index | number | – | Current slide (controlled). |
defaultIndex | number | 0 | Initial slide (uncontrolled). |
onIndexChange | (index: number) => void | – | Called when the slide changes. |
autoPlay | number | 0 | Auto-advance interval in ms (0 = off); pauses on hover and focus. |
loop | boolean | true | Wrap around at the ends. |
label | string | 'Carousel' | Accessible name. |
previousLabel | string | 'Previous slide' | Wording of the previous button (aria-label and tooltip). |
nextLabel | string | 'Next slide' | Wording of the next button (aria-label and tooltip). |
dotLabel | (index: number) => string | (i) => `Go to slide ${i + 1}` | Aria-label of the dot for slide index (0-based). |
className | string | '' | Extra classes for the root element. |