Carousel

A compound component for cycling through a series of slides with keyboard navigation, dot indicators, and optional auto-play.

Installation

npx dafink-ui add carousel

Demo

1
2
3
4
5
Slide 1 of 0

Composition

<Carousel>
<CarouselContent>
<CarouselItem />
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
<CarouselDots />
</Carousel>

Props

NameTypeDefaultDescription
loopbooleanfalseWraps from the last slide back to the first (and vice versa).
autoPlaybooleanfalseAutomatically advances slides at the specified interval.
intervalnumber4000Milliseconds between auto-advances when autoPlay is enabled.
aria-labelstring"Carousel"Accessible name for the carousel region landmark. Override with a descriptive value.
classNamestring""Additional classes on the root element.

Accessibility

Carousel uses native tab order, not roving tabindex: the Previous button, Next button, each dot, and any focusable slide content are all individually reachable stops in plain document order. Left/Right arrow keys are handled at the carousel region and work as long as focus is anywhere inside it, regardless of which control currently has focus.

KeyFunction
right arrowAdvances to the next slide, from anywhere focus is inside the carousel region.
left arrowGoes to the previous slide, from anywhere focus is inside the carousel region.
tabMoves focus to the next focusable element (Previous, Next, a dot, or slide content) in native document order.
shift+tabMoves focus to the previous focusable element in native document order.
enterActivates the focused Previous, Next, or dot button.
spaceActivates the focused Previous, Next, or dot button.