# Slider (`<z-slider>`)

> Scroll-snap carousel for variable-width items, with drag/swipe, seamless looping, set-based paging, centered mode, and autoplay.

- **Kind:** controller
- **Category:** navigation
- **Status:** experimental
- **Inherits:** `CarouselBase`, `Controller`, `Base`

> **Experimental:** Under active stabilization; API and layout behavior may change before graduating to stable.

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `sets` | `boolean` | `false` | — | Navigates by viewport-wide sets of items instead of one item at a time; snap points land on set anchors. |
| `center` | `boolean` | `false` | — | Centers the active item in the viewport instead of aligning it to the start. |
| `active-mode` | `'all' \| 'first'` | `'all'` | — | Which visible items get the active class: `all` visible items (default) or only the `first`. |

### Inherited from `CarouselBase`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `active` | `number` | — | `CarouselBase` | Index of the active slide; setting it navigates to that slide. `-1` before initialization. |
| `finite` | `boolean` | `false` | `CarouselBase` | Stops at the first/last slide instead of looping; boundary controls are hidden and disabled. |
| `autoplay` | `boolean` | `false` | `CarouselBase` | Advances automatically every `autoplay-interval` ms; ticks pause while hovered, focused within, dragging, or the document is hidden. |
| `autoplay-interval` | `number` | `7000` | `CarouselBase` | Autoplay interval in milliseconds (minimum 500, default 7000). |
| `no-pause-on-hover` | `boolean` | `false` | `CarouselBase` | Keeps autoplay running while the pointer is over the carousel. |
| `no-drag` | `boolean` | `false` | `CarouselBase` | Disables pointer drag/swipe navigation. |
| `duration` | `number` | `0` | `CarouselBase` | Transition duration in ms. When unset, the component default (slider 350, slideshow 450) divided by `velocity` is used; an explicit `0` makes transitions instant. |
| `velocity` | `number` | `1` | `CarouselBase` | Speed multiplier applied to the default duration (default 1); ignored when `duration` is set. |
| `easing` | `string` | `''` | `CarouselBase` | CSS easing for programmatic transitions; empty uses the component default. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `active`. Default `stl` target: `host-inner`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `active` | `z-active` | ✓ | — | Class applied to active slides and nav controls (default `z-active`). |
| `dragging` | `z-dragging` | ✓ | — | Class applied to the items list while a pointer drag is in progress (default `z-dragging`). |
| `next` | — | ✓ | — | Marker part for the next-arrow control (`data-part="next"`). |
| `previous` | — | ✓ | — | Marker part for the previous-arrow control (`data-part="previous"`). |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-slider:before-change` | ✓ | `Record<string, unknown>` | Cancelable; fires before the active slide changes. Detail carries `index`, `previousIndex`, `slide`, `previousSlide`, `value`, and `dir`. |
| `z-slider:before-hide` | ✓ | `Record<string, unknown>` | Cancelable; fires before the outgoing slide hides, with the same detail as `before-change`. |
| `z-slider:before-show` | ✓ | `Record<string, unknown>` | Cancelable; fires before the incoming slide shows, with the same detail as `before-change`. |
| `z-slider:change` | — | `Record<string, unknown>` | Fires when the active slide changes, with the same detail as `before-change`. |
| `z-slider:hidden` | — | `Record<string, unknown>` | Fires after the outgoing slide's transition completes. |
| `z-slider:hide` | — | `Record<string, unknown>` | Fires when the outgoing slide starts hiding. |
| `z-slider:mount` | — | `Record<string, unknown>` | Fires when deferred template content is mounted into the container. |
| `z-slider:show` | — | `Record<string, unknown>` | Fires when the incoming slide starts showing. |
| `z-slider:shown` | — | `Record<string, unknown>` | Fires after the incoming slide's transition completes. |

## Methods

| Method | Params | Returns | Description |
| --- | --- | --- | --- |
| `count()` | — | `number` | Returns the number of slides. |
| `index()` | — | `number` | Returns the current active index. |
| `next()` | `animate?: boolean = true` | `Promise<boolean>` | Advances to the next slide (wraps unless `finite`); resolves to whether the index changed. |
| `previous()` | `animate?: boolean = true` | `Promise<boolean>` | Moves to the previous slide (wraps unless `finite`); resolves to whether the index changed. |
| `refresh()` | — | `void` | Re-measures the track and re-initializes navigation, autoplay, and observers. |
| `show()` | `target: number \| 'next' \| 'previous' \| 'first' \| 'last' \| string`, `animate?: boolean = true` | `Promise<boolean>` | Navigates to an index, `next`/`previous`/`first`/`last`, or a slide's `data-value`/id; resolves to whether the index changed. Cancelable `before-*` events can veto it. |
| `startAutoplay()` | — | `void` | Starts the autoplay timer; a no-op unless `autoplay` is enabled. |
| `stopAutoplay()` | — | `void` | Stops the autoplay timer. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-auto-nav-item` | — | `descendant` | `config` | Marks nav items generated by the carousel; a fully auto nav is rebuilt to match the slide count. |
| `data-autoplay` | — | `descendant` | `config` | On a slide video: plays it while the slide is active. |
| `data-fn` | `template` | `descendant` | `config` | Marks a deferred `<template>` child whose content is mounted into the container on demand. |
| `data-keep-playing` | — | `descendant` | `config` | On a slide video: keeps it playing when the slide becomes inactive. |
| `data-part` | `next`, `previous` | `descendant` | `marker` | Marks arrow controls: `data-part="previous"` and `data-part="next"`. |
| `data-value` | — | `descendant` | `read-only` | On a slide: its command value, usable as a `show()` target and carried in event detail. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-dragging` | `state` | `.z-slider` | State class on the track during a drag; disables snap and smooth scrolling. |
| `.z-slider` | `root` | `z-slider` | Root class, also styled on the `z-slider` host. |
| `.z-slider-container` | `element` | `.z-slider` | Optional outer wrapper clipping the track. |
| `.z-slider-items` | `element` | `.z-slider` | The scrollable, scroll-snapping track holding the slides. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `ArrowLeft` / `ArrowRight` | Previous/next slide (direction flips in RTL). | — |
| `ArrowLeft` / `ArrowRight` / `ArrowUp` / `ArrowDown` / `Home` / `End` | Move within a nav tablist; Home/End jump to the first/last slide. | Focus is inside a `.z-slider-nav` list. |

## Accessibility

> The host is a `role="region"` with `aria-roledescription="carousel"`; slides are `tabpanel`s (with nav) or `group`s labeled `n of total`.

> Nav lists become `role="tablist"` with roving tabindex; arrow controls get `aria-controls` and localized labels.

> The items list is `aria-live="polite"`, switched to `off` while autoplay runs.

## Notes

- The track is `.z-slider-items` (or `[data-part="items"]` / `[data-part="list"]`); nav is `.z-slider-nav` (or `[data-part="nav"]`).
- Nav controls target slides with `data-slider-item="<index|value>"`; `data-slider-ignore` excludes a child from the slide list.
- Looping reorders slides with CSS `order` and scroll compensation, so the DOM order (and tab order) stays canonical; `finite` disables it.
- Drag navigation suppresses the follow-up click and ignores interactive content (buttons, inputs, `[data-no-drag]`, …).
- Slide videos with `data-autoplay` play while active; others pause unless `data-keep-playing` is set.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Slideshow](https://next.0build.dev/docs/components/slideshow.md)
- [Switcher](https://next.0build.dev/docs/components/switcher.md)
