npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@data-slot/carousel

v1.0.2

Published

Headless carousel component for vanilla JavaScript. Accessible, unstyled, and built on native scrolling.

Readme

@data-slot/carousel

Headless carousel component for vanilla JavaScript. Accessible, unstyled, and built on native scrolling.

Installation

bun add @data-slot/carousel
# or
npm install @data-slot/carousel

Quick Start

<div data-slot="carousel" data-default-index="0">
  <div data-slot="carousel-content">
    <div data-slot="carousel-item">Slide 1</div>
    <div data-slot="carousel-item">Slide 2</div>
    <div data-slot="carousel-item">Slide 3</div>
  </div>

  <button data-slot="carousel-previous">Previous</button>
  <button data-slot="carousel-next">Next</button>
</div>

<script type="module">
  import { create } from "@data-slot/carousel";

  const controllers = create();
</script>

API

create(scope?)

Auto-discover and bind all carousel roots in a scope (document by default).

import { create } from "@data-slot/carousel";

const controllers = create(); // CarouselController[]

createCarousel(root, options?)

Create a controller for a specific root element.

import { createCarousel } from "@data-slot/carousel";

const carousel = createCarousel(element, {
  defaultIndex: 1,
  orientation: "horizontal",
  drag: true,
  loop: false,
  onIndexChange: (index) => console.log(index),
});

Data Attributes

JS options take precedence over data attributes.

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | data-default-index | number | 0 | Initial active index | | data-orientation | horizontal \| vertical | horizontal | Carousel orientation | | data-drag | boolean | false | Enable pointer drag/swipe navigation | | data-loop | boolean | false | Enable soft-wrap loop navigation |

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | defaultIndex | number | 0 | Initial active slide index | | orientation | "horizontal" \| "vertical" | "horizontal" | Axis used for keyboard navigation and scrolling | | drag | boolean | false | Enable pointer drag/swipe navigation on the scroll container | | loop | boolean | false | Enable soft-wrap for prev/next/keyboard/API navigation | | onIndexChange | (index: number) => void | undefined | Called when active slide changes |

Controller

| Method / Property | Description | |-------------------|-------------| | prev() | Navigate to previous slide | | next() | Navigate to next slide | | goTo(index) | Navigate to specific slide | | index | Current active index | | count | Total number of slides | | canScrollPrev | Whether previous navigation is available | | canScrollNext | Whether next navigation is available | | destroy() | Cleanup listeners and observers |

Navigation Animation

Carousel navigation uses native smooth scrolling by default for:

  • prev() / next() / goTo()
  • keyboard navigation (Arrow*, Home, End)
  • inbound carousel:set events
  • optional carousel-previous / carousel-next button clicks

When the user prefers reduced motion (prefers-reduced-motion: reduce), navigation falls back to instant scroll behavior.

When drag is enabled, the carousel also supports pointer drag/swipe gestures and snaps to the nearest slide on release.

Events

Outbound (on root)

| Event | Detail | Description | |-------|--------|-------------| | carousel:change | { index: number } | Fires when active index changes |

Inbound (on root)

| Event | Detail | Description | |-------|--------|-------------| | carousel:set | { index?: number, action?: "next" \| "prev" } | Programmatically navigate carousel |

root.addEventListener("carousel:change", (event) => {
  console.log(event.detail.index);
});

root.dispatchEvent(
  new CustomEvent("carousel:set", { detail: { action: "next" } }),
);

root.dispatchEvent(
  new CustomEvent("carousel:set", { detail: { index: 2 } }),
);

Required Slots

  • carousel (root)
  • carousel-content (scroll container)
  • carousel-item (direct slide children)

Optional Slots

  • carousel-previous
  • carousel-next

Styling

The component is unstyled and relies on CSS hooks:

[data-slot="carousel"] { position: relative; }

[data-slot="carousel-content"] {
  display: flex;
  overflow: auto;
  scroll-snap-type: x mandatory;
}

[data-slot="carousel"][data-dragging="true"] {
  cursor: grabbing;
}

[data-slot="carousel-item"] {
  flex: 0 0 100%;
  scroll-snap-align: start;
}

[data-slot="carousel-item"][data-state="active"] {
  opacity: 1;
}

[data-slot="carousel-item"][data-state="inactive"] {
  opacity: 0.75;
}

For vertical carousels, switch scroll-snap-type to y mandatory and use column layout.

Accessibility

The carousel shows one slide at a time. Inactive slides are marked aria-hidden and inert, which removes them and their content from the accessibility tree and the tab order until they become active. Size slides to fill the viewport, as in the styling example above; a layout that shows several slides at once would hide visible neighbours from assistive technology.

The controller automatically sets:

  • root: role="region", aria-roledescription="carousel"
  • item: role="group", aria-roledescription="slide", aria-label="n of total"
  • item state: data-state, aria-hidden, inert
  • root drag state: data-dragging="true" during an active pointer drag
  • nav controls: disabled / aria-disabled synced to scrollability

License

MIT