Saltar al contenido
DS

Componentes · Interacción

Carrusel <Carousel>

Una fila de tarjetas que se desliza con el dedo, la rueda o los botones.

import Carousel from '@vivla-cms/ds/primitives/Carousel.astro'

Ejemplos

Props

Props de Carousel
Prop Valores Por defecto Para qué
id * string — Element id; the track is ${id}-track (the buttons' aria-controls).
label * string — Accessible name of the region, e.g. «Fotos de Casa Taula».
start number 0 Slide centred on load, 0-based (default 0).
slideWidth SlideWidth — Slide width in percent of the carousel width: { mobile: 80, desktop: 69 }.
bleed boolean true Full-bleed rail: controls inset by the page gutter (default true).
track string — dataLayer event pushed when a prev / next click moves the rail, e.g. carousel_nav.
trackLabel string — track_label param of that event, e.g. listing_gallery.
progress boolean false A 2 px progress line above the buttons that fills from the left as the rail scrolls (Landings Performance 158:5830; grows instead of sliding since the 05/11 web review). Below md the line stands alone and the buttons hide (Components_Web ficha gallery 401:2150, mobile). Track line-subtle (Foundations border/subtle, #CCC on light grounds), thumb on-surface — Jaime 16/10. Hidden, like the buttons, when everything fits.
controls linediscnone 'disc' disc = the 56 px Icon button (default, Components_Web 154:94) · line = the older thin arrows (56 px, 72 from 48rem; Web 2026 ficha 234:1860 — no caller left, kept for one release) · none = no buttons and no progress line (swipe / keyboard only).
inset gutterwide — align="start" only, from 48rem: percent of the carousel width of the previous card left cut at the left edge at rest (the first card at the start). Default 0 = slides snap to the page gutter. Where the first slide starts (align="start"): the page gutter, which is where every Container starts. Since 05/11 the page has no cap, so wide (the left edge of a capped Container width="wide", added on 15/10 when a 1728 px Mac showed the title at 148 and the cards at 40) IS the gutter: it is kept as an alias so callers and the ds.vivla.dev example keep working. Prefer the default.
peek number 0 —
align centerstart 'center' center (default) snaps the slide to the middle · start snaps it to the left edge of the rail, inset by the page gutter, so a row of cards reads from the left (Landings Performance carousels).
gap gridm 'grid' align="start" only: the space between slides. grid (default) = the Foundations medianil, 20 at every width (Layout 768:47) · m = space/m, 32 (Conoce VIVLA team rail, phone 1590:2492).

Slots: contenido

Notas del código

El comentario de cabecera de Carousel.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.

horizontal scroll-snap rail with peeking neighbours and prev / next buttons under the slides, at the edges. The buttons are the Components_Web «Icon button» (74zqbI8QliQL1oyXyFbsBT 154:94, the ficha gallery «PDP/house photo» 401:2132): a 56 px disc at every width, icon 20, action/primary fill → action/primary/bg-hover, disabled #ccc / #867c79, focus ring 2 px separated 2 px.

<Carousel id="listing-gallery" label={`Fotos de ${home.name}`} start={1}>
  {photos.map((photo) => (
    <figure><Media {...photo} aspect="3/2" radius="none" /></figure>
  ))}
</Carousel>

Every direct child of the slot is one slide: the rail sizes and snaps it (centre snap, one slide per swipe). Slide width is a share of the carousel's own width: 80 % on phones and 69 % from 48rem by default (slideWidth), and the track is padded so the first and last slides can centre too.

Card rows (Landings Performance 158:5830, 14/10): align="start" snaps each slide to the page gutter instead of the centre (the row reads from the left), progress adds a 2 px line that fills from the left as the rail scrolls: the visible share at the start, the whole line at the end (it grows, it never slides — web review 05/11). At either end of the rail the disc there is aria-disabled and takes the disabled roles (Foundations «Slider arrow» 1202:1661: grey disc, grey arrow, the same in light and dark), keeping its full-strength focus ring. controls="none" drops the buttons and the progress line: a swipe-only row (the photo row «Haz de Baqueira tu segundo hogar» 88:1117). Keyboard (← / → on the focused track) and the slide semantics stay.

peek (from 48rem, align="start" only): every resting position leaves that share of the carousel width of the previous card cut at the left edge — at the start, the FIRST card is the one cut (Landings Performance 83:625: first card at x −118 of 1512 → peek={7.8}). The track drops its left gutter and each slide snaps with a negative scroll-margin-left, so swipe, buttons and keys all land on the same peeked positions.

<Carousel id="destinos" label="Destinos" align="start" progress controls="disc"
          peek={7.8} slideWidth={{ mobile: 68, desktop: 33, desktopMax: 31.3125 }}>…</Carousel>

Behaviour:

  • Never autoplays and never loops: it moves only on swipe, scroll, the
buttons or the keyboard, and stops at both ends (the button there is
`aria-disabled`, so focus is never dropped).
  • Keyboard: the track is focusable; ← / → move one slide, Home / End jump
to the ends, only while the track itself has focus (a control inside a
slide keeps its keys, so it is never scrolled away while focused). The
buttons work with Enter / Space. The focus ring follows the nearest theme
(`outline-focus`), so it stays visible on the accent band.
  • Motion: programmatic moves use scroll-behavior: smooth, which the
reduced-motion rule in base.css turns into an instant jump. A width change
(rotation, resize) re-centres the current slide without animation.
  • Hidden: a carousel bound while hidden (closed Dialog, collapsed
Accordion, inactive Tabs panel) keeps its `start` slide and centres it the
first time it gets a width.
  • No JS: a plain scrollable rail with a visible scrollbar; the buttons stay
`hidden`. The script hides the scrollbar once it has bound the controls,
and hides the controls whenever everything fits.

Moving from code (e.g. a lightbox opening at the photo that was clicked): set data-start before the carousel binds, or dispatch on the root, before or after showing it:

root.dispatchEvent(new CustomEvent('ds-carousel:go', { detail: { index: 4, instant: true } }))

index is 0-based and clamped; instant skips the smooth scroll; announce (default false) reads the new position in the live status.

Analytics: with track, a click on prev / next that actually moves pushes { event: track, track_direction: 'prev' | 'next', track_label } to the GTM dataLayer (track_label only with trackLabel). Clicks on a disabled end button, keys and swipes push nothing.

Accessibility (APG carousel): the root is a labelled region with aria-roledescription «carrusel» / «carousel»; the script gives each non-interactive slide role="group", aria-roledescription «diapositiva» / «slide» and a «3 de 7» name (an existing role or aria-label is kept), and a polite live status reads the position after a button or key move. Every string comes from uiLabel (carousel, carouselSlide, carouselSlideOf, carouselPrev, carouselNext). Slides get data-current="true" on the centred one for styling (e.g. dimming neighbours). Colours are roles only: put it in a themed <Section>.

bleed (default true) is for a rail that runs edge to edge of the page: the controls row then sits inside the page gutter. Inside a Container pass bleed={false}.

Dónde se usa

8 veces en 5 archivos de la web y los bloques del CMS.

Ver los archivos
esc