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/accordion

v0.2.6

Published

Headless accordion component for vanilla JavaScript. Accessible, unstyled, tiny.

Readme

@data-slot/accordion

Headless accordion component for vanilla JavaScript. Accessible, unstyled, tiny.

Installation

npm install @data-slot/accordion

Quick Start

<div data-slot="accordion">
  <div data-slot="accordion-item" data-value="one">
    <button data-slot="accordion-trigger">Section One</button>
    <div data-slot="accordion-content">Content for section one</div>
  </div>
  <div data-slot="accordion-item" data-value="two">
    <button data-slot="accordion-trigger">Section Two</button>
    <div data-slot="accordion-content">Content for section two</div>
  </div>
</div>

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

  const controllers = create();
</script>

API

create(scope?)

Auto-discover and bind all accordion instances in a scope (defaults to document).

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

const controllers = create(); // Returns AccordionController[]

createAccordion(root, options?)

Create a controller for a specific element.

import { createAccordion } from "@data-slot/accordion";

const accordion = createAccordion(element, {
  multiple: true,
  defaultValue: ["one"],
  collapsible: true,
  onValueChange: (values) => console.log(values),
});

Options

| Option | Type | Default | Description | | --------------- | --------------------------- | ----------- | ------------------------------------------------------- | | multiple | boolean | false | Allow multiple items open at once | | defaultValue | string \| string[] | undefined | Initially expanded item(s) | | collapsible | boolean | true | Whether items can be fully collapsed (single mode only) | | onValueChange | (value: string[]) => void | undefined | Callback when expanded items change |

Data Attributes

Options can also be set via data attributes on the root element. JS options take precedence.

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | data-multiple | boolean | false | Allow multiple items open at once | | data-default-value | string | none | Initially expanded item | | data-collapsible | boolean | true | Whether items can be fully collapsed |

Boolean attributes: present or "true" = true, "false" = false, absent = default.

<!-- Multiple items can be open, starting with "one" expanded -->
<div data-slot="accordion" data-multiple data-default-value="one">
  ...
</div>

<!-- Single mode that cannot be fully collapsed -->
<div data-slot="accordion" data-collapsible="false">
  ...
</div>

Controller

| Method/Property | Description | | ----------------- | ----------------------------------------------- | | expand(value) | Expand an item by value | | collapse(value) | Collapse an item by value | | toggle(value) | Toggle an item by value | | value | Currently expanded values (readonly string[]) | | destroy() | Cleanup all event listeners |

Markup Structure

<div data-slot="accordion">
  <div data-slot="accordion-item" data-value="unique-id">
    <button data-slot="accordion-trigger">Trigger</button>
    <div data-slot="accordion-content">Content</div>
  </div>
</div>

Styling

Use data-state attributes for CSS styling:

/* Closed state */
[data-slot="accordion-content"][data-state="closed"] {
  display: none;
}

/* Open state */
[data-slot="accordion-content"][data-state="open"] {
  display: block;
}

/* Animate with grid */
[data-slot="accordion-item"] {
  display: grid;
  grid-template-rows: auto 0fr;
  transition: grid-template-rows 0.3s;
}

[data-slot="accordion-item"][data-state="open"] {
  grid-template-rows: auto 1fr;
}

[data-slot="accordion-content"] {
  overflow: hidden;
}

With Tailwind:

<div
  data-slot="accordion-item"
  class="grid grid-rows-[auto_0fr] data-[state=open]:grid-rows-[auto_1fr] transition-[grid-template-rows]"
>
  <button data-slot="accordion-trigger">...</button>
  <div data-slot="accordion-content" class="overflow-hidden">...</div>
</div>

Keyboard Navigation

| Key | Action | | ----------------- | ------------------------------ | | Enter / Space | Toggle focused item | | ArrowDown | Move focus to next trigger | | ArrowUp | Move focus to previous trigger | | Home | Move focus to first trigger | | End | Move focus to last trigger |

Events

Listen for changes via custom events:

element.addEventListener("accordion:change", (e) => {
  console.log("Expanded items:", e.detail.value);
});

License

MIT