Carousel

A row of slides on the browser's own scrolling and scroll snap: touch, trackpad, wheel and keyboard scroll it natively, and buttons and indicators page through it.

  • vig-carousel
  • ng-template[vigCarouselItem]
Import
import { Carousel, CarouselItem } from '@vigdx/ui/carousel';

Basic

Pass items and a vigCarouselItem template; bind the items to vigCarouselItemOf to type let-item . [(page)] is the zero-based page in view; it changes once scrolling settles, so a swipe emits pageChange once. A page holds as many slides as are in view, so page counts pages, not items (unlike the activeIndex of a galleria); a resize that changes the slides per view recomputes it. Name the carousel with labels.ariaLabel . Give slide images width / height and loading="lazy" after the first.

Page: 1

Several per view, circular

perView takes a number or { base, sm, md, lg, xl } , resolved by container queries on the carousel's own width (sm from 40rem, md 48rem, lg 64rem, xl 80rem), so the server render and the first paint already have the right layout. A page is that many slides; swipes snap page by page. circular wraps previous and next around.

Autoplay

Off by default. autoplay ( true for 5 seconds, or milliseconds) turns the pages and wraps at the end. It pauses while the pointer is over the carousel, while it is pressed and while the user scrolls it; when focus enters it, rotation stops for good and only the stop/start button (first in the tab order, WCAG 2.2.2) starts it again, as the APG asks. It starts stopped when the system asks for reduced motion.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="carousel"][data-part="root"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="carousel"]

Carousel styling hooks
Part Element data-state
root The host, a role="region" with aria-roledescription="carousel" ; rotating while autoplay turns pages. rotating, idle
rotation Stop/start button of autoplay , first in the tab order. playing, paused
viewport Positions the previous/next buttons over the track. —
previous Previous page button. —
next Next page button. —
track The focusable scroll-snap row; --vig-carousel-gap sets the gap between slides. —
slide One slide, a group named "3 of 10"; active while in view. active, inactive
status Visually hidden polite status announcing the settled page. —
indicators The group of indicator buttons. —
indicator One page button; the current one has aria-current="true" and a wider dot. active, inactive

Accessibility

  • The APG carousel pattern: a role="region" with aria-roledescription="carousel", slides as groups with aria-roledescription="slide" named "3 of 10". The role descriptions and every name are labels keys, so they translate.
  • The track is one tab stop and scrolls natively with the arrow keys, Page Up/Down and Home/End; links and buttons inside slides keep their own keys, and focusing one scrolls its slide into view. Previous and next come before the slides in reading order.
  • Indicators are buttons with aria-current="true" on the current page rather than tabs: several slides can be in view and every slide stays reachable by scrolling, which the tabs pattern (one visible panel, the others hidden) would not allow. The current dot is also wider, so it does not rely on color; in forced colors it is drawn in Highlight.
  • A visually hidden polite status announces "Slide 3 of 10" once scrolling settles (scrollend, with a debounced scroll fallback), whether a button, an indicator or a swipe moved it; nothing is announced while autoplay rotates.
  • Autoplay pauses on hover, while pressed and while the user scrolls; focus entering the carousel stops it until the rotation button is pressed. The direction comes from the carousel's own computed direction, so a plain dir="rtl" ancestor is enough. With a responsive perView the indicators stay invisible (their space kept) until the browser resolved how many pages there are.
  • When previous or next becomes disabled while focused, focus moves to the other button. Every button is at least 24px (44px on touch screens). Smooth scrolling is used only without prefers-reduced-motion.

API

vig-carousel component

A row of slides on native scrolling and CSS scroll snap, following the APG carousel pattern: touch, trackpad, mouse wheel and the keyboard (the focusable track) scroll it natively; previous/next buttons and one indicator button per page (aria-current) scroll it from script. Slides are groups named "3 of 10"; a polite status announces where the carousel settled.

perView shows several slides at once, by container width; circular wraps the buttons around; autoplay (off by default) rotates through the pages, pauses while hovered, pressed or scrolled by the user, stops for good when focus enters the carousel (APG), offers a stop/start button (WCAG 2.2.2) and starts stopped under prefers-reduced-motion.

Example :
<vig-carousel [items]="products" [perView]="{ base: 1, sm: 2, lg: 3 }" [labels]="{ ariaLabel: 'New arrivals' }">
  <ng-template vigCarouselItem [vigCarouselItemOf]="products" let-product>
    <app-product-card [product]="product" />
  </ng-template>
</vig-carousel>
Carousel props
Name Type Default Description
autoplaynumber0

Automatic rotation, off by default: true turns pages every 5 seconds, a number every that many milliseconds. It always wraps around.

circularbooleanfalse

Previous on the first page goes to the last, next on the last to the first.

indicatorsbooleantrue

One indicator button per page below the slides. Default true.

itemsreadonly T[][]

The slides' data; each renders through the vigCarouselItem template.

labelsPartial<CarouselLabels>—

Texts (i18n) over the locale defaults.

page model number0

Two-way: the zero-based page in view, set once scrolling settles (so a swipe emits pageChange once). With one slide per view a page is a slide; with several it counts pages, unlike a galleria's activeIndex, which is an item index. A resize that changes the slides per view recomputes it.

perViewnumber | CarouselPerView1

Slides per view: a number, or a CarouselPerView by container width. Default 1.

CarouselItem

ng-template[vigCarouselItem] directive

The template of each slide. Bind the carousel's items to vigCarouselItemOf (like ngForOf) to type let-item.

Example :
<ng-template vigCarouselItem [vigCarouselItemOf]="products" let-product let-i="index">
  <app-product-card [product]="product" />
</ng-template>
CarouselItem props
Name Type Default Description
vigCarouselItemOfreadonly T[] | null | undefinedundefined

Type-only: the items the template renders, so let-item is typed. Not read at runtime.

Are you sure?