Carousel

A slideshow component for cycling through a series of slides — with prev/next controls, indicator dots, optional captions, autoplay, crossfade, and full keyboard, swipe, and controlled-state support.

Import

tsx
import { Carousel, CarouselItem, CarouselCaption } from '@metatoy/bootstrap-styled';

Basic

Wrap each slide in a CarouselItem. By default the carousel renders prev/next controls and indicators, is uncontrolled, and wraps from the last slide back to the first. Add a CarouselCaption to overlay text on a slide.

Autoplay & crossfade

ride="carousel" (or ride alone) starts autoplay; interval sets the dwell time in milliseconds. Add fade to crossfade between slides instead of sliding, and pause="hover" (the default) to pause cycling while the pointer is over the carousel.

Controlled

Drive the active slide yourself with activeIndex + onSelect. Set interval={null} to disable autoplay. This is how you sync a carousel to external thumbnails or buttons.

Props

PropTypeDefaultDescription
activeIndexnumberControlled active slide index.
defaultActiveIndexnumberUncontrolled initial index.
onSelect(index: number, direction: 'next' | 'prev') => void
onSlide(event: CarouselSlideEvent) => voidFired when a slide transition BEGINS (Bootstrap `slide.bs.carousel`). Distinct from `onSlid`, which fires once the transition settles.
onSlid(event: CarouselSlideEvent) => voidFired when a slide transition SETTLES (Bootstrap `slid.bs.carousel`).
rideboolean | 'carousel'Autoplay. `'carousel'` (or true) cycles automatically.
intervalnumber | nullAutoplay dwell time in ms. Default 5000. Set 0/null to disable.
keyboardbooleanLeft/Right arrow navigation when focused. Default true.
pause'hover' | false`'hover'` pauses autoplay while hovered. Default `'hover'`.
wrapbooleanWrap from last→first (and first→last). Default true.
touchbooleanTouch/swipe (pointer) gestures advance the carousel. Default true.
fadebooleanCrossfade instead of slide (`.carousel-fade`).
indicatorsbooleanRender the indicator dots. Default true.
controlsbooleanRender the prev/next controls. Default true.
darkbooleanDark control/indicator/caption theming (`.carousel-dark`).
childrenReact.ReactNode

CarouselItem accepts an optional per-slide interval (ms) plus all native <div> attributes; CarouselCaption is a styled <div>. The onSlide / onSlid callbacks fire when a transition begins / settles with a { from, to, direction } payload.

Theming

Carousel reads Bootstrap’s carousel tokens, including --bs-carousel-control-icon-filter, --bs-carousel-indicator-active-bg, and --bs-carousel-caption-color. Setting dark applies the .carousel-dark treatment (dark controls, indicators, and captions) for use over light slides.

Accessibility

The carousel root is a labelled region; controls are real <button>s with descriptive labels and the indicators expose the current slide. Left/Right arrow keys navigate when the carousel is focused (keyboard, default on). Autoplay pauses on hover and on focus. For content that conveys meaning, prefer non-autoplaying carousels (or a visible pause control) so users who need more time aren’t rushed.

Explore in Ladle