Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

carousel-wc

Scroll carousel with prev/next buttons, dot indicators, autoplay, keyboard navigation, and ARIA.

Overview

A scroll-snap carousel with full progressive enhancement. Without JavaScript it renders as a simple scrollable row. With JS it adds prev/next buttons, dot indicators, autoplay, looping, keyboard navigation, and ARIA roles.

Usage

Wrap slide elements inside <carousel-wc>. Each direct child becomes a slide. Give each carousel a name with aria-label or aria-labelledby: the carousel is a region landmark, and unnamed ones all fall back to "Carousel", which makes several on one page indistinguishable.

Autoplay with Looping

Add autoplay and loop to cycle slides automatically. Autoplay renders a pause/play rotation control as the first control in the carousel. Pausing with it sticks until the user presses play again. While rotation is on, it also pauses while the pointer is over the carousel or keyboard focus is inside it, and resumes when they leave. When prefers-reduced-motion is active, autoplay is off entirely and no rotation control appears.

Multi-item Carousel

Set item-width="auto" to show multiple items at once with a gap. Each item keeps its content width. For equal widths, pass a CSS length such as item-width="18rem" or item-width="40%".

No Indicators

Set indicators="false" to hide dot indicators.

Attributes

AttributeValuesDefaultDescription
autoplayboolean—Auto-advance slides and render a pause/play rotation control (ignored under reduced motion)
autoplay-delaynumber—Delay between auto-advance in milliseconds (default 5000)
loopboolean—Loop back to start after last slide
indicatorsstring—Show dot indicators; "false" hides them
item-widthstring—Slide width: "full" (default), "auto" (content width), or a CSS length such as "18rem"
gap"xs", "s", "m", "l", "xl"—Gap between slides
startnumber—Initial slide index
persiststring—localStorage key for position persistence
transition"fade", "slide", "scale"—View Transition animation between slides
data-label-trackstringSlidesAccessible name of the focusable slide track

Required Structure

ElementRequiredDescription
any child elementsyesEach direct child becomes a slide

Events

EventDetailDescription
carousel-wc:change{ index, slide }Fired once per slide change (scroll settling is debounced)
carousel-wc:play—Fired when the autoplay timer starts or resumes (including after a hover/focus suspension ends)
carousel-wc:pause—Fired when the autoplay timer stops: explicit pause, or a hover/focus/touch suspension
carousel-wc:slides-changed{ slides, source: 'property' }Fired after the slides property rebuilds the carousel

carousel-wc:play and carousel-wc:pause follow the autoplay timer. They also fire when hover or focus suspends rotation and when rotation resumes afterwards.

JavaScript API

Property / MethodTypeDescription
element.currentIndexnumberCurrent slide index (read-only)
element.slideCountnumberTotal number of slides (read-only)
element.playingbooleanWhether the autoplay timer is running right now (read-only; false while hover or focus suspends it)
element.slidesArrayGet the slides as data, or assign records to rebuild (see Data API)
element.next()methodGo to next slide
element.prev()methodGo to previous slide
element.goTo(index, smooth)methodJump to specific slide (smooth defaults to true)
element.play()methodStart or resume rotation, adding the rotation control if needed (no-op under reduced motion)
element.pause()methodStop rotation until play() or the rotation control resumes it
element.reset()methodReturn to initial slide, clear persistence

Data API

The slides property swaps the slide set from data. Each record needs html (the slide content as an HTML string). id becomes the slide element's id. label replaces the default "n of total" slide label. Assigning rebuilds the carousel at slide 0 (or start) and fires carousel-wc:slides-changed. If you assign before the element is in the document, the carousel builds once when it connects.

The data API is HTML-only: content is assigned with innerHTML. Sanitize untrusted strings before you assign them.

Keyboard Navigation

Focus the carousel track (Tab into it), then use arrow keys:

KeyAction
ArrowLeftPrevious slide
ArrowRightNext slide
HomeFirst slide
EndLast slide

In right-to-left documents the arrow keys follow the visual direction: ArrowLeft goes to the next slide, ArrowRight to the previous one, and the prev/next chevrons are mirrored.

Accessibility

ARIA Roles

The component uses role="region" with aria-roledescription="carousel". An authored aria-label or aria-labelledby names the region; without one it falls back to "Carousel". Each slide has role="group" with aria-roledescription="slide" and a label like "1 of 4", unless the slide already has an aria-label. The slide track is a focus stop for the arrow keys: it has role="group" and is named "Slides" (set data-label-track on the carousel to change or translate the name). Dot indicators are simple buttons inside a role="group" named "Slide indicators"; only the active dot carries aria-current="true".

Rotation Control

With autoplay, a pause/play button comes first in the carousel's reading order, following the APG carousel pattern and WCAG 2.2.2 (Pause, Stop, Hide). Its accessible name says what it will do: "Pause automatic slide show" or "Start automatic slide show".

Live Region

A visually hidden live region announces "Slide n of total". It is aria-live="off" while slides rotate on their own, so screen readers are not interrupted on every tick. It becomes aria-live="polite" when rotation is paused or suspended, and on carousels without autoplay.

Reduced Motion

When prefers-reduced-motion is active (or the page sets data-motion-reduced on the root element), autoplay is completely disabled, no rotation control is rendered, and scroll behavior uses instant transitions.

Styling

Override the button and dot styles using the .carousel-rotate, .carousel-prev, .carousel-next, and .carousel-dot classes.

Progressive Enhancement

Without JavaScript, <carousel-wc> renders as a horizontal scrollable row using the :not(:defined) fallback. Once JS registers the component, controls and indicators appear.

View Transitions

Add transition to switch from scroll-snap to View Transition animations. When active, the carousel uses a stacked-grid layout and animates between slides using the View Transitions API.

ValueEffect
fade (default)Crossfade between slides
slideDirectional slide — forward when advancing, backward when retreating
scaleScale down old slide, scale up new slide

Dual-Mode Behavior

Without transition, the carousel uses scroll-snap with IntersectionObserver — slides are arranged in a horizontal row and the user scrolls between them. With transition, the carousel switches to a stacked CSS Grid layout where slides occupy the same grid cell and are shown/hidden with View Transition animations.

Related

↑