Carousel: Controlled
Pass index and onIndexChange. Swiping updates your state and your state scrolls the carousel.
index = 2
This adds the example as components/examples/carousel/controlled.tsx, together with the Carousel component and the HextaUI theme tokens it needs.
pnpm dlx shadcn@latest add https://hextaui.com/r/carousel-controlled.jsonTo add only the component, follow the Carousel installation.
Props in this example
The Carousel props this example sets, from the API reference.
| Prop | Type | Default |
|---|---|---|
index | number | – |
onIndexChange | (index: number) => void | – |
Every prop is in the Carousel API reference.
- API
- Several per view
- Dots and counter
- Autoplay
- Thumbnails
- Vertical
- Rewind and start index
- Links and focusable content
- Adding and removing slides
- Nested
- Long content and a single slide
- Right to left
See them all, with keyboard support and accessibility notes, on the Carousel page.
- ButtonButtons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- Number flowAnimated numbers where only the changed digits spin, with any Intl format and locale.
- AccordionStacked headings that each reveal a panel, with height motion you can reverse mid-way and panels that stay searchable while closed.
- Aspect ratioA box that holds its shape before media loads, shimmers while loading, fades the media in and falls back when it fails.
- CollapsibleA panel that shows and hides with height motion you can reverse mid-way, without jumping the layout.
- ResizablePanels you can drag apart, with a quiet divider that wakes up on hover, sizes that glide on reset or collapse, and layouts that persist.