Flow / Carousel
A carousel for stepping through a sequence of slides, with previous and next controls and optional looping.
VdFlow Component
1 / 3
v-model is the slide index. Slots are #slide-0 through #slide-n. The exposed controller is go, prev, next, and index.
Basic Carousel
Fade Variant
Autoplay with Indicators
Compact Size
Large Size
API Reference
Wiring
import { ref } from 'vue';
import { useFlow } from "@vanduo-oss/vd3";
const root = ref<HTMLElement | null>(null);
const flow = useFlow(root); // wires every .vd-flow inside root; cleanup on unmount
// programmatic control via returned FlowApi:
// flow.next(el), flow.prev(el), flow.goTo(el, 2), flow.refresh()
// react to slide changes
root.value?.addEventListener('flow:change', (e) => {
console.log('slide', e.detail.current); // { current, previous, total }
});CSS Classes
| Class | Description | Type |
|---|---|---|
.vd-flow | Base carousel container — required | Base |
.vd-carousel | Alias for .vd-flow | Base |
.vd-flow-track | Inner wrapper holding all slides; handles translation | Structure |
.vd-flow-slide | Individual slide element within the track | Structure |
.vd-flow-prev | Previous-slide navigation button | Control |
.vd-flow-next | Next-slide navigation button | Control |
.vd-flow-indicators | Container for dot indicators; one button per slide | Control |
.vd-flow-fade | Crossfade transition instead of horizontal slide | Modifier |
.vd-flow-compact | Reduced padding and height for compact layouts | Size |
.vd-flow-lg | Increased padding and height for hero-style carousels | Size |
Data Attributes
| Attribute | Description | Default |
|---|---|---|
data-vd-autoplay | Enable automatic slide advancement when set to "true" | false |
data-vd-interval | Time in milliseconds between auto-advances | 5000 |
data-vd-loop | Loops back to the first slide after the last; set to "false" to disable | true |
VdFlow Component API
| Prop / Slot / Exposed | Description |
|---|---|
v-model (modelValue) | number — zero-based active slide index. |
:total | number — total number of slides to render. |
#slide-{i} | Named scoped slot for slide i (0 to total - 1); receives { index }. |
Exposed (template ref) | { go(index), prev(), next(), index: Ref<number> } — imperative slide controls. |
Composable API (useFlow)
| Symbol | Description |
|---|---|
useFlow(root) | Composable — wires every .vd-flow / .vd-carousel inside the root ref (prev/next, indicators, keyboard, touch swipe, autoplay) and returns a FlowApi controller. |
goTo(el, index) | FlowApi method — jump the given .vd-flow element to zero-based slide index (wraps when data-vd-loop is enabled, clamps otherwise). |
next(el) / prev(el) | FlowApi methods — step the given .vd-flow element forward or backward one slide. |
refresh() | FlowApi method — re-scans root for newly added .vd-flow elements and syncs slide/indicator ARIA. |
(automatic cleanup) | Listeners, live regions, and autoplay timers are cleared on component unmount. |
Events
| Event | Description | Detail |
|---|---|---|
flow:change | Fired on the .vd-flow element after a slide transition completes | { current, previous, total } |
Accessibility
- Navigation buttons include
aria-labelattributes for screen readers - Indicator buttons use
aria-label="Go to slide N"for identification - Active indicator receives
aria-current="true"and.is-activeclass - Autoplay pauses on
:hoverand:focus-withinto respect user interaction - Keyboard navigation: ArrowLeft / ArrowRight move between slides when focused
- The carousel container uses
role="region"andaria-roledescription="carousel" - Each slide uses
role="group"andaria-roledescription="slide"