Featured carousel
ProThe large carousel at the top of a media or store page: one slide in front with whole slides set back beside it, moved by a swipe, side arrows or keys, and by itself only with a Pause control. Not an M3 component (@windmorph/react-pro).
import { FeaturedCarousel, FeaturedCarouselSlide, FeaturedCarouselPlaceholder, useFeaturedCarouselSlide } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
The large carousel at the top of a media or store page: one slide in front, whole slides beside it set back and peeking in, moved by a swipe, by arrows at its sides or by the keyboard, and able to move by itself within what WCAG 2.2.2 allows. A slide holds anything: a picture, words, links, buttons, a video.
M3's carousel doesn't move by itself and has no Previous and Next, no indicator and no controls inside an item, so this is a Pro component. Use the core Carousel for M3's browsing row of pictures; a Shelf for a row of cards; a MediaViewer to look through photos full screen.
Behaviour
- Its layout follows its own width: under 600px a slide is 88% wide at 4:5; to 840px, 90% wide and at least 448px tall; from 840px, 16:9, at most 70% of the window's height. Heights are least heights, so longer words lengthen a slide. The first slide stands at the start edge, the last at the end edge, the others centred.
- The current slide is the one showing most of itself, measured on each scroll frame, so size and brightness hand over during a move. It carries
data-current; every other slide isinert. When a slide stops being current with focus inside it, focus moves first to the arriving slide. - By hand: a swipe or a trackpad (native scrolling, snapping to a slide); a press anywhere beside the current slide brings that side's slide forward; Previous and Next at the sides for a mouse, at any width; and Left and Right while the pointer is over it or focus is in it (left to anything with arrow keys of its own). Without a mouse, a visually hidden pair of buttons beside the dots shows on keyboard focus. It goes round by default; with
loop={false}the arrow that leads nowhere is dimmed andaria-disabled. A second press during a move goes on from where the first was heading. onIndexChangereports each new slide with what moved it:person,timerorapp. Anindexyou set moves it without an announcement and without stopping the timer.- Under the slides, dots say how many there are, the current one wider (not buttons: hidden from assistive tech); past
maxDots(20) a count (“3 of 30”) takes their place. One slide has no arrows, no dots and no timer; no slides draw nothing.
Moving by itself
- Off unless you pass
autoAdvance(7 seconds a slide, or{ interval }). The current dot fills over the slide's time. - It waits, and goes on from where it was, while a mouse is over the slides, while less than half of it is in view, while the tab is hidden, and while a slide holds it.
- The slides stop moving by themselves when keyboard focus comes in and when the person moves them by any means; media in the slide they went to plays on. The Pause control, first in the Tab order though drawn under the slides, stops everything that moves by itself, media in a slide included, until Play (
pausedandonPausedChangeare that control's state). - A slide that plays something passes
mediaand readsuseFeaturedCarouselSlide():mayMovesays whether it may play,hold()holds the timer while it does, andnext()moves the carousel on when it ends. - Under reduced motion it never moves by itself, media in a slide isn't told it may play, and the Pause control isn't there.
Loading and failed
FeaturedCarouselPlaceholder, a server component, draws the carousel's frame, one slide's box by the same classes and the foot (foot={false} leaves it out), with your content in the slide (classNames.slide styles it): a Skeleton while loading, a notice and Try again when it fails. Every slide is in the server's HTML, the first one current.
When not to use
For M3's browsing row of pictures, use a Carousel; for a row of cards, a Shelf; to look through photos full screen, a Media viewer.
See also
- Carousel: A scrollable row of items that resize along keylines: multi-browse, uncontained, multi-aspect, hero or full-screen.
- Shelf: One row of cards that scrolls sideways, with part of the next card showing at its end and Previous and Next at its sides for a mouse. Not an M3 component (@windmorph/react-pro).
- Media viewer: A full-screen viewer for a set of photos: swipe between them, zoom, and read each caption and position. Not an M3 component (@windmorph/react-pro).