Carousel
A slideshow that shows one slide at a time (WAI-ARIA APG carousel with previous/next buttons and a slide picker).
- Slides are the Carousel.Item (CarouselItem) children, written directly in the Carousel or in Fragments. Other children are not rendered (a development warning says so). A component that renders Carousel.Item itself is not recognised: write the Carousel.Item in the Carousel and put the component inside it.
- Previous/Next stay focusable at the ends (aria-disabled), so keyboard focus is not lost.
- The slide picker is a group of buttons named "Slide n of m"; the active one has aria-current="true".
- Inactive slides are aria-hidden and inert, so neither Tab nor a screen reader reaches their content.
- With autoPlay, a Pause/Start control comes first (WAI-ARIA APG): rotation pauses while focus is inside the carousel (in most browsers also after a click on one of its controls) or the pointer is over its content, activating Start rotates at once, and the live region is silent (aria-live="off") while slides rotate. Without loop rotation ends at the last slide and stays stopped until the control's Start is activated (or the number of slides changes, or loop is turned on).
- Right-to-left layouts slide the other way and mirror the Previous/Next chevrons: the direction is read from the rendered element (its dir prop, the nearest ancestor's dir, WaveProvider dir or the document's), so an LTR section inside an RTL page stays LTR throughout.
- Name the carousel with aria-label or aria-labelledby (the fallback name is "Carousel"). The built-in names and role descriptions are English: labels and autoPlayLabels translate them.
- The controls are layered over the slides inside the carousel's own stacking context, so they never paint over page headers that stay in view while the page scrolls.
- groupSize shows several slides per page, draggable lets the pointer drag them, and a thumbnail on a Carousel.Item turns the picker into a row of thumbnails.
- controlsLayout places the Previous and Next buttons over the slides (overlay, overlay-wide) or beside them (inline, inline-wide); Carousel.Button replaces the built-in button of its direction with one of your own glyph.
- The slides glide to the new page over 300 ms; motion="fade" cross-fades them instead (one slide per page), motion={null} turns the motion off and motionDuration times it. Under reduced motion, or below a WaveProvider with motion="none" (unless motion is set), the page changes at once.
Compound access (Carousel.Item, Carousel.Button) needs a client module; React Server Components import the flat names CarouselItem and CarouselButton instead.
Examples
Default
export const Default: Story = {};With Loop
export const WithLoop: Story = {
args: { loop: true, children: tintedSlides },
};Auto Play
export const AutoPlay: Story = {
args: { autoPlay: true, loop: true, autoPlayInterval: 4000, children: tintedSlides },
};Auto Play Once
export const AutoPlayOnce: Story = {
args: { autoPlay: true, autoPlayInterval: 3000, children: tintedSlides },
};Right To Left Section
export const RightToLeftSection: Story = {
args: { children: tintedSlides },
render: (args) => (
<div dir="rtl">
<Carousel {...args} />
</div>
),
};Localized
export const Localized: Story = {
args: {
'aria-label': 'Angebote',
lang: 'de',
autoPlay: true,
loop: true,
autoPlayLabels: { pause: 'Rotation anhalten', play: 'Rotation starten' },
labels: {
previous: 'Vorherige Folie',
next: 'Nรคchste Folie',
picker: 'Folie auswรคhlen',
slide: (index, total) => `Folie ${index + 1} von ${total}`,
},
children: tintedSlides,
},
};Interactive Slides
export const InteractiveSlides: Story = {
args: {
children: ['Plan', 'Build', 'Ship'].map((step) => (
<Carousel.Item key={step}>
<div className={`${slideClass} bg-wave-muted text-wave-foreground`}>
<h3 className="text-wave-subtitle-2">{step}</h3>
<Button appearance="primary">Learn about {step.toLowerCase()}</Button>
</div>
</Carousel.Item>
)),
},
};Controlled
Active slide: 1
export const Controlled: Story = {
render: (args) => <ControlledCarousel {...args} />,
};Groups
export const Groups: Story = {
args: { groupSize: 3, children: manySlides },
};Auto Size
export const AutoSize: Story = {
args: {
groupSize: 'auto',
align: 'center',
children: manySlides.map((slide, i) => (
<Carousel.Item key={i}>
<div
className={`${slideClass} w-40 bg-wave-card text-wave-card-foreground border border-wave-border`}
>
Slide {i + 1}
</div>
</Carousel.Item>
)),
},
};Draggable
export const Draggable: Story = {
args: { draggable: true, groupSize: 2, children: manySlides },
};Thumbnails
export const Thumbnails: Story = {
args: { children: thumbSlides },
};Controls Layouts
export const ControlsLayouts: Story = {
render: (args) => (
<div className="flex flex-col gap-6">
{(['overlay', 'overlay-wide', 'inline', 'inline-wide'] as const).map((controlsLayout) => (
<Carousel
key={controlsLayout}
{...args}
controlsLayout={controlsLayout}
aria-label={controlsLayout}
autoPlay
>
{neutralSlides}
</Carousel>
))}
</div>
),
};Custom Buttons
export const CustomButtons: Story = {
render: (args) => (
<Carousel {...args} controlsLayout="inline">
{neutralSlides}
<Carousel.Button direction="previous">โน</Carousel.Button>
<Carousel.Button direction="next">โบ</Carousel.Button>
</Carousel>
),
};Elevated
export const Elevated: Story = {
args: { appearance: 'elevated' },
};Motion
export const Motion: Story = {
render: ({ motion: _motion, motionDuration, ...args }) => (
<div className="flex flex-col gap-6">
{carouselMotions.map((option) => (
// The story renders one carousel per case; every other arg is forwarded.
<Carousel
key={option.label}
{...args}
aria-label={option.label}
motion={option.motion}
motionDuration={option.motionDuration ?? motionDuration}
>
{tintedSlides}
</Carousel>
))}
</div>
),
};Change Cause
Last change: no change yet
export const ChangeCause: Story = {
args: { draggable: true, loop: true, children: tintedSlides },
render: function ChangeCauseCarousel(args) {
const [last, setLast] = React.useState('no change yet');
return (
<div className="flex flex-col gap-3">
<Carousel
{...args}
onValueChange={(index, details) => {
args.onValueChange?.(index, details);
setLast(`slide ${index + 1}, caused by ${details?.reason}`);
}}
/>
<p className="text-wave-body-1">Last change: {last}</p>
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value | number | No | Controlled index of the active slide: with | |
defaultValue | number | No | 0 | Default active slide index for uncontrolled usage. |
onValueChange | (index: number, details?: CarouselChangeDetails) => void | No | Called with the new index when the active slide changes (not when it stays the same): the first slide of the new page when | |
groupSize | number | 'auto' | No | 1 | How many slides one page shows: a number, or |
align | 'start' | 'center' | 'end' | No | 'start' | With |
draggable | boolean | No | false | Lets the pointer drag the slides (mouse, touch and pen). The track follows the pointer and, on release, the page changes when the drag passed a quarter of the width or left fast, else it snaps back; the direction follows the carousel's. Under |
controlsLayout | 'overlay' | 'inline' | 'overlay-wide' | 'inline-wide' | No | 'overlay' | Where the Previous and Next buttons go. |
appearance | 'flat' | 'elevated' | No | 'flat' |
|
autoPlay | boolean | No | false | Rotates the slides automatically. A Pause/Start control is rendered as the first focusable element. Rotation pauses while focus is anywhere inside the carousel (the control included; clicking a control also moves focus there in most browsers) or the pointer is over it (except over the control), and resumes when they leave, unless rotation is stopped. Activating Start rotates at once, also while focus stays on the control; moving focus on to other content pauses again. It starts stopped when the user prefers reduced motion. Without |
autoPlayInterval | number | No | 5000 | Interval in milliseconds between auto-play transitions. |
autoPlayLabels | CarouselAutoPlayLabels | No | Accessible names of the rotation control. | |
labels | CarouselLabels | No | Accessible names of the Previous and Next buttons, the slide picker and the slides (also announced by the live region), and the role descriptions of the carousel and its slides, for localization. Unset members keep their English defaults. | |
loop | boolean | No | false | Whether the carousel loops back to the first slide after the last. |
motion | 'slide' | 'fade' | null | No | 'slide' | How the carousel moves between pages: |
motionDuration | number | No | 300 | How long the slide or the fade takes, in milliseconds. Fluent's |
slotProps | { autoPlayButton?: SlotPart<'button'>; track?: SlotPart<'div'>; slide?: SlotPart<'div'>; previousButton?: SlotPart<'button'>; nextButton?: SlotPart<'button'>; picker?: SlotPart<'div'>; pickerButton?: SlotPart<'button'>; pickerIndicator?: SlotPart<'span'> } | No | Props for the elements the carousel draws around and between its slides, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref attached. Every attribute the carousel sets on a part is locked, and so are its handlers: yours runs first, and | |
ref | React.Ref<HTMLDivElement> | No |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
autoPlayButtontrackslidepreviousButtonnextButtonpickerpickerButtonpickerIndicatorCarousel.ItemCarousel.Button
Stable class names
| Part | Class |
|---|---|
root | wave-carousel |
autoPlayButton | wave-carousel__auto-play-button |
viewport | wave-carousel__viewport |
track | wave-carousel__track |
slide | wave-carousel__slide |
previousButton | wave-carousel__previous-button |
nextButton | wave-carousel__next-button |
picker | wave-carousel__picker |
pickerButton | wave-carousel__picker-button |
pickerIndicator | wave-carousel__picker-indicator |