Skip to content

BbCarousel

Slides the reader swipes through, photos or product cards, with arrows, dots, a thumbnail strip and autoplay.

import { BbCarousel } from 'bitboss-ui';

On this page

Use it for

Use BbCarousel for a short run of slides the reader steps through: a listing's photos, a row of product cards, onboarding screens. Swipe, drag, arrows and keys all work out of the box.

Use something else when

  • BbGallery, when a photo should open full screen
  • BbTabs, when each view has a name the reader picks
  • A grid or a BbTable, when the reader compares the items side by side

Always give the carousel a label: screen readers announce it as a carousel of that name.

Passthrough

Hover or tap a part to outline it. The toggles turn on loading, errors and warnings where the component has them; only parts get a row.

Show photos

Pass the photos as items, each with a src and an alt. They render as cover-cropped images, with no slot to write.

The crop is the --ratio local, 16 / 9 by default; set it in a class ([--ratio:3/2]). A photo without alt is treated as decorative. The photos in view and their neighbours load at once, the rest as the reader gets near them.

Without items, each child of the default slot is one slide.

Several per view

Set per-view, or the --per-view local when it changes per breakpoint. A fraction shows a peek of the next slide, so a phone reader knows there is more.

Use the slide slot for anything that is not a bare photo; item is typed as your entry. With several in view the carousel moves a page at a time, and there is one dot per page.

Set a value with the prop or with the local, never both (the bitboss-ui/carousel-prop-or-local lint rule flags it). The spacing is --gap, never a gap-* class.

A thumbnail strip

Bind two carousels to the same v-model and add picker to the strip. A tap on a thumbnail moves the photo above, with no sync code.

v-model is the current slide, 0-based. A picker hides its own arrows and dots: the thumbnails are the control, and each one is a button named by its alt.

Loop and autoplay

loop makes the run endless. autoplay turns the slides on a timer: true is every 5 seconds, or pass milliseconds.

Autoplay pauses on hover, on focus and off screen, and never runs for readers who ask for reduced motion. It always shows a pause button, at the start of the dots row, with a target of at least 24px for a mouse and 44px on touch. Keep it for decorative rotation: content the reader must see should not move on its own.

Content on the slides

The overlay slot lays content over every slide and moves with it: a caption, a counter, a badge, a save button. Place it yourself; the layer is the size of the slide.

Put text over a photo on a scrim, and keep the bottom clear for the dots. Name every button for what it does. For a title or a price under each slide instead, use slide:footer (or slide:header above it).