Skip to content

Carousel

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

NameTypeRequiredDefaultDescription
valuenumberNo

Controlled index of the active slide: with groupSize above 1, the first slide of the shown page. A value in the middle of a page shows that page and out-of-range values show the nearest one.

defaultValuenumberNo0

Default active slide index for uncontrolled usage.

onValueChange(index: number, details?: CarouselChangeDetails) => voidNo

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 is above 1. The second argument says what caused the change and carries its event (Fluent UI's onActiveIndexChange(event, { type, event }), whose type is the reason here).

groupSizenumber | 'auto'No1

How many slides one page shows: a number, or 'auto' to show as many as fit the width of the carousel (the slides keep their own width, which must be equal). Previous, Next, the picker (one button per page), looping and autoplay move by page, and the slides of the shown page form one arrow-key focus group. With 1 each slide fills the width, as before.

align'start' | 'center' | 'end'No'start'

With groupSize="auto", where the shown page sits when its slides do not fill the width.

draggablebooleanNofalse

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 motion="fade" the slides do not follow the pointer (they share one place): the same drag still changes the page on release, and the slides cross-fade. The click that ends a drag is not delivered to the slide, and a vertical swipe still scrolls the page. Dragging pauses autoplay like the pointer over the carousel does. The buttons and the keyboard stay the way to operate the carousel without a pointer.

controlsLayout'overlay' | 'inline' | 'overlay-wide' | 'inline-wide'No'overlay'

Where the Previous and Next buttons go. overlay floats round buttons over the slides; overlay-wide makes them full-height strips at the edges; inline puts them in a row with the slides, outside them; inline-wide is inline with full-height buttons. The rotation control stays the first focusable element at the start corner in every layout.

appearance'flat' | 'elevated'No'flat'

elevated rounds the corners and adds a shadow.

autoPlaybooleanNofalse

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 loop, rotation ends at the last slide: the control shows Start, and rotation stays stopped (also after the user moves back to an earlier slide) until Start is activated, which continues from the shown slide, or from the first one while the last is shown. The end is tied to its cause: when the number of slides changes (slides loaded later) or loop is turned on, rotation continues on its own, unless the user stopped it with Pause.

autoPlayIntervalnumberNo5000

Interval in milliseconds between auto-play transitions.

autoPlayLabelsCarouselAutoPlayLabelsNo

Accessible names of the rotation control.

labelsCarouselLabelsNo

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.

loopbooleanNofalse

Whether the carousel loops back to the first slide after the last.

motion'slide' | 'fade' | nullNo'slide'

How the carousel moves between pages: slide glides the slides in from the side of the page order (mirrored in right-to-left layouts), fade cross-fades them in place, and null turns the motion off (the page changes at once). Fluent's motion; its object form with a duration is not offered: use motionDuration. fade needs one slide per page: with groupSize above 1 or 'auto' the slides slide, and a development warning says so. Under fade a drag still changes the page on release, but the slides do not follow the pointer. Below a WaveProvider with motion="none" the carousel does not move unless this prop is set. Either motion is off while the user prefers reduced motion. The root renders the motion it resolves from this prop, groupSize and the provider as data-motion (slide, fade or none); reduced motion leaves it unchanged.

motionDurationnumberNo300

How long the slide or the fade takes, in milliseconds. Fluent's duration is a different unit (Embla's unitless speed, 20 to 60), so a value ported from Fluent is far too short.

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 preventDefault() in yours skips the carousel's handling of the event, except where a part says its work always runs. A part takes no children (the carousel draws their content). Each part locks, unset where the carousel sets none, role, tabIndex, data-roving-container (it would take the slides out of their arrow-key order), data-carousel-rotation (the rotation control's marker: focus inside a part that carries it would not pause the rotation) and hidden, inert and aria-hidden. A Carousel.Button you write replaces the built-in button of its direction and takes its props directly: previousButton and nextButton reach only the built-in buttons. The viewport around the track has no part.

refReact.Ref<HTMLDivElement>No

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • autoPlayButton
  • track
  • slide
  • previousButton
  • nextButton
  • picker
  • pickerButton
  • pickerIndicator
  • Carousel.Item
  • Carousel.Button

Stable class names

PartClass
rootwave-carousel
autoPlayButtonwave-carousel__auto-play-button
viewportwave-carousel__viewport
trackwave-carousel__track
slidewave-carousel__slide
previousButtonwave-carousel__previous-button
nextButtonwave-carousel__next-button
pickerwave-carousel__picker
pickerButtonwave-carousel__picker-button
pickerIndicatorwave-carousel__picker-indicator