Carousel
vig-carousel ng-template[vigCarouselItem]
import { Carousel, CarouselItem } from '@vigdx/ui/carousel';Basic
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
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"]
| Part | Element | data-state |
|---|---|---|
root | role="region" with aria-roledescription="carousel" ; rotating while autoplay turns pages. | rotating, idle |
rotation | autoplay , first in the tab order. | playing, paused |
viewport | — | |
previous | — | |
next | — | |
track | --vig-carousel-gap sets the gap between slides. | — |
slide | active while in view. | active, inactive |
status | — | |
indicators | — | |
indicator | aria-current="true" and a wider dot. | active, inactive |
Accessibility
- The APG carousel pattern: a
role="region"witharia-roledescription="carousel", slides as groups witharia-roledescription="slide"named "3 of 10". The role descriptions and every name arelabelskeys, 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 debouncedscrollfallback), 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 plaindir="rtl"ancestor is enough. With a responsiveperViewthe 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
Carousel
vig-carouselA 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.
<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>| Name | Type | Default | Description |
|---|---|---|---|
autoplay | number | 0 | Automatic rotation, off by default: |
circular | boolean | false | Previous on the first page goes to the last, next on the last to the first. |
indicators | boolean | true | One indicator button per page below the slides. Default |
items | readonly T[] | [] | The slides' data; each renders through the |
labels | Partial<CarouselLabels> | — | Texts (i18n) over the locale defaults. |
page | number | 0 | Two-way: the zero-based page in view, set once scrolling settles (so a
swipe emits |
perView | number | CarouselPerView | 1 | Slides per view: a number, or a |
| Name | Payload | Description |
|---|---|---|
pageChange | number | Two-way: the zero-based page in view, set once scrolling settles (so a
swipe emits |
| Signature | Description |
|---|---|
goTo(page: number): void | Scrolls to a zero-based page. |
next(): void | Scrolls to the next page (the first one from the last, when |
previous(): void | Scrolls to the previous page (the last one from the first, when |
CarouselItem
ng-template[vigCarouselItem]The template of each slide. Bind the carousel's items to
vigCarouselItemOf (like ngForOf) to type let-item.
<ng-template vigCarouselItem [vigCarouselItemOf]="products" let-product let-i="index">
<app-product-card [product]="product" />
</ng-template>| Name | Type | Default | Description |
|---|---|---|---|
vigCarouselItemOf | readonly T[] | null | undefined | undefined | Type-only: the items the template renders, so |