Projection
Where the flick was aimed
Velocity handoff
No seam on release
Elastic edges
The end of the set, felt
Reduced motion
Becomes a scroll-snap strip
classNameCarouselDotsCarouselPreviousdisabledimport { Carousel, CarouselDots, CarouselNext, CarouselPrevious, CarouselSlide, CarouselViewport } from "@/components/ui/carousel"
const slides = [
{ id: "1", title: "Projection", detail: "Where the flick was aimed" },
{ id: "2", title: "Velocity handoff", detail: "No seam on release" },
{ id: "3", title: "Elastic edges", detail: "The end of the set, felt" },
{ id: "4", title: "Reduced motion", detail: "Becomes a scroll-snap strip" },
]
export function Techniques() {
return (
<Carousel label="Gesture techniques">
<CarouselViewport>
{slides.map((slide) => (
<CarouselSlide key={slide.id} label={slide.title}>
<div className="rounded-xl border p-3">
<p className="text-sm font-medium">{slide.title}</p>
<p className="text-xs text-muted-foreground">{slide.detail}</p>
</div>
</CarouselSlide>
))}
</CarouselViewport>
<div className="flex items-center justify-between">
<CarouselDots labels={slides.map((s) => s.title)} />
<div className="ml-auto flex gap-1.5">
<CarouselPrevious />
<CarouselNext />
</div>
</div>
</Carousel>
)
}Usage
import {
Carousel,
CarouselDots,
CarouselNext,
CarouselPrevious,
CarouselSlide,
CarouselViewport,
} from "@/components/ui/carousel"
const slides = [
{ id: "1", title: "Projection" },
{ id: "2", title: "Velocity handoff" },
{ id: "3", title: "Elastic edges" },
]
export function Highlights() {
return (
<Carousel label="Highlights">
<CarouselViewport>
{slides.map((slide) => (
<CarouselSlide key={slide.id} label={slide.title}>
<div className="h-40 rounded-lg border p-4">{slide.title}</div>
</CarouselSlide>
))}
</CarouselViewport>
<div className="flex items-center justify-between">
<CarouselDots labels={slides.map((s) => s.title)} />
<div className="flex gap-1.5">
<CarouselPrevious />
<CarouselNext />
</div>
</div>
</Carousel>
)
}Examples
Projection
Where the flick was aimed
Velocity handoff
No seam on release
Elastic edges
The end of the set, felt
Reduced motion
Becomes a scroll-snap strip
import {
Carousel,
CarouselViewport,
CarouselSlide,
CarouselDots,
CarouselPrevious,
CarouselNext,
} from '@/components/ui/carousel';
export function Example() {
return (
<Carousel label="Gesture techniques">
<CarouselViewport>
{slides.map((slide) => (
<CarouselSlide key={slide.id} label={slide.title}>
<Card slide={slide} />
</CarouselSlide>
))}
</CarouselViewport>
<div className="flex items-center justify-between">
<CarouselDots labels={slides.map((s) => s.title)} />
<div className="flex gap-1.5">
<CarouselPrevious />
<CarouselNext />
</div>
</div>
</Carousel>
);
}Projection
Where the flick was aimed
Velocity handoff
No seam on release
Elastic edges
The end of the set, felt
Reduced motion
Becomes a scroll-snap strip
// Positions are read from the DOM, not derived from a nominal slide width, so a
// mixed set lands as accurately as an even one.
<CarouselSlide label={slide.title} className="w-[45%]">
<Card slide={slide} />
</CarouselSlide>Projection
Where the flick was aimed
Velocity handoff
No seam on release
Elastic edges
The end of the set, felt
Reduced motion
Becomes a scroll-snap strip
const [index, setIndex] = useState(0);
<Carousel label="Highlights" index={index} onIndexChange={setIndex}>
{/* ... */}
</Carousel>
<p>Slide {index + 1} of {slides.length}</p>Notes
Motion tier
Needs motion. add --all skips it; install with add --motion or by name.
Snapping
On release, the velocity is projected 200ms forward from the strip's position and the strip snaps to the slide that lands in. A flick advances; a slow drag that stops short does not.
Slide sizes
Slide positions are measured from layout, so gaps set by class, uneven widths and container padding all work. A resize re-aligns the strip to the current slide. The dots count the measured slides.
Reduced motion
The drag is replaced by a native scroll-snap strip. Dots and arrows jump instead of animating. Honours the OS setting and an app-level <MotionConfig reducedMotion>.
When to use it
- A short set viewed one at a time: highlights, screenshots, testimonials. Suits touch-first surfaces.
- For content to compare side by side, use a grid.
- Do not hide content that matters; off-screen slides read as optional.
API
details.reason says why, and details.cancel() keeps the current slide.CarouselSlide elements, placed directly inside.Agent
Inside an AgentProvider, it appears in agent.snapshot() as carousel.
Reads
labelThe Carousel's label.
valueThe current slide's label, or its number when unnamed.
itemsEvery slide's label, in order.
disabledTrue when the carousel is disabled.
Actions
goTo("Velocity handoff")Moves by label, or by number from 1. A miss lists the slides.
An agent's move runs through onIndexChange like a drag or dot press. isAgentChange(details) is true for it; details.cancel() refuses it and the agent is told the app refused. A disabled carousel refuses on its own. The dots and arrows are not listed separately.
await agent.act({
steps: [{ ref: "Gesture techniques", action: "goTo", args: ["Velocity handoff"] }],
})Accessibility
- The root is role="group" with aria-roledescription="carousel" and your label.
- Each slide is a group with aria-roledescription="slide", named with its position: "2 of 4: Velocity handoff".
- The dots are buttons in a group named "Choose a slide"; the current one has aria-current.
- The set does not wrap. The arrow at either end is disabled.
- The strip has no arrow-key handling. Keyboard users move with the dots and arrows.