Carousel
Basic usage
Root holds a viewport (scroll container) and slides (data-mv-carousel-item). Add tabIndex={0} (or tabindex="0" in HTML) so ArrowLeft / ArrowRight work when the carousel is focused.
Keyboard
Put tabindex="0" (or tabIndex={0}) on the carousel root so it can receive focus, then use ArrowLeft / ArrowRight to go to the previous or next slide while focus is inside the carousel (including on the root). The handler skips arrow keys when focus is ...
Focus the carousel (click inside it or press Tab), then use ← / → to move between slides. Arrow keys are ignored while typing in inputs.
Scrollbar visible
By default the viewport and thumbnail strip use hidden native scrollbars (scrolling still works). Set data-mv-carousel-show-scrollbar="true" on the root—or pass showScrollbar: true to getOrCreateInstance—to show them. This example also adds mv-scrollab...
Overlay arrows
Add prev/next buttons as overlay controls inside a relative carousel wrapper so they stay visible and easy to click.
Pagination
Place data-mv-carousel-pagination on a wrapper; each dot is data-mv-carousel-pagination-item in slide order. Active item gets aria-current="true".
Autoplay
Autoplay respects prefers-reduced-motion: reduce (timer is not started). Hover and focus-in pause autoplay when data-mv-carousel-pause-on-hover is true (default).
Infinite loop
At the last slide, Next wraps to the first; at the first, Previous wraps to the last.
RTL
Set dir="rtl" on the root (or rely on document direction). Arrow keys follow visual next / previous in RTL.
Multiple slides
Use CSS (min-w-[45%], etc.) so several slides peek into the viewport; the component still advances one slide index per next/prev.
Centered
data-mv-carousel-centered="true" scrolls the active slide with inline: "center".
Draggable
Pointer-drag on the viewport scrolls horizontally. Not combined with snap in this API: when data-mv-carousel-snap="true", draggable behavior is disabled.
Drag horizontally on the track (snap is off).
Auto height
data-mv-carousel-auto-height="true" sets the viewport height from the active slide (see ResizeObserver in implementation).
Snap
Add Tailwind snap-x / snap-mandatory on the viewport and snap-center on items; enable data-mv-carousel-snap="true" so drag is not attached.
Viewport uses scroll snap; draggable is disabled when snap is on.
Info
data-mv-carousel-current and data-mv-carousel-total show 1-based current index and slide count.
Thumbnails (horizontal)
data-mv-carousel-thumbnails wraps controls; each data-mv-carousel-thumbnail maps to a slide by DOM order.
Thumbnails (vertical)
Same behavior with a column layout.
Destroy & reinitialize
Use MVCarousel.getInstance(root)?.dispose() then MVCarousel.getOrCreateInstance(root) after dynamic updates.