ui-kit0.0

Display

Carousel

Browse slides by swipe, arrows or dots.

Product images

A native scroll-snap track: swipe, trackpad and mouse wheel work the way the platform does, with no drag library. The buttons and dots drive the same scroll position.

When to use

  • A set of related images or cards where only a few fit at once.
  • Content that is optional: anything important should also be reachable without the carousel.

Not for steps in a flow (use a stepper), for tabbed content, or for a single hero that must be seen.

Several slides per view

Set --ui-carousel-per-view on the root, responsively if you like (sm:[--ui-carousel-per-view:2]). Slide width accounts for --ui-carousel-gap. Dots count the positions the track can actually rest on.

Autoplay and loop

autoplay advances on a timer. It pauses while the pointer is over the carousel, focus is inside it or the tab is hidden, and never runs under reduced motion. loop makes Next on the last position rewind to the first and keeps both buttons enabled.

API

Carousel

PropTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'Scroll direction. Vertical needs a height.
loopbooleanfalseRewind from the last position to the first (and back).
autoplayboolean | numberfalsetrue advances every 5 s; a number is the interval in ms.
onIndexChange(index: number) => void—Called when the first visible position changes, however it changed.
aria-labelstring—Name of the carousel, e.g. “Product photos”.

CarouselContent / CarouselItem

PropTypeDefaultDescription
viewportClassNamestring—CarouselContent: class for the scrolling viewport (className styles the track).
basisstring—CarouselItem: width (height when vertical) as a CSS length. Or use className, e.g. basis-2/3.

CarouselPrevious and CarouselNext take Button props (variant, size) and sit inside Carousel beside the content. CarouselDots renders nothing when everything fits.

Keyboard

KeyAction
← / →Previous / next slide while focus is anywhere inside the carousel (↑ / ↓ when vertical).
TabMoves between the track, the buttons and the dots.
Enter / SpaceActivates a button or dot.

Accessibility

  • Follows the WAI-ARIA carousel pattern: role="region" with aria-roledescription="carousel"; each slide is role="group" with aria-roledescription="slide" and a label “n of m”.
  • At the ends the buttons are aria-disabled (not removed from the tab order, so focus is not lost).
  • Dots are buttons labelled “Go to slide n”, the current one marked aria-current.
  • Autoplay pauses on hover, focus and in hidden tabs, and is off under reduced motion.
  • The track is a focusable scrollable region, so keyboard users can always scroll it.

Motion

  • Previous, next and dots scroll smoothly to the slide; snapping is the browser’s.
  • The active dot stretches into a pill on the snappy spring.
  • Reduced motion: jumps instead of gliding; autoplay is disabled.