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

@gnireeg/accordion

v0.1.19

Published

Accessible accordion web component with smooth animations, keyboard support, and nested accordion groups

Downloads

1,954

Readme

@gnireeg/accordion

Accessible accordion web component with smooth animations, keyboard support, and nested accordion groups.

Features

  • ✨ Smooth expand/collapse animations
  • ♿ Full accessibility (ARIA attributes, keyboard navigation)
  • 🎨 Customizable animation timing and easing
  • 📦 Zero dependencies
  • 🎯 TypeScript support
  • 🔄 Accordion groups with mutual exclusion
  • 🪆 Support for nested accordions
  • 🎪 Custom events for state changes

Installation

npm install @gnireeg/accordion

Usage

Basic Accordion

<script type="module">
  import '@gnireeg/accordion';
</script>

<accordion-item>
  <button slot="trigger-container">Click to expand</button>
  <div>Your content here</div>
</accordion-item>

<!-- Start expanded -->
<accordion-item open>
  <button slot="trigger-container">Already open</button>
  <div>This content is visible by default</div>
</accordion-item>

Selective Trigger (Advanced)

Use the accordion-trigger attribute to specify which element should toggle the accordion. This allows you to place additional interactive elements alongside the trigger:

<accordion-item>
  <div slot="trigger-container" class="flex gap-2">
    <!-- Only this button toggles the accordion -->
    <button accordion-trigger class="flex-1">
      Expand details
    </button>

    <!-- These buttons won't toggle the accordion -->
    <button onclick="edit()">Edit</button>
    <button onclick="delete()">Delete</button>
  </div>

  <div>Your content here</div>
</accordion-item>

Note: If no element with the accordion-trigger attribute is found, the entire trigger container will toggle the accordion (backward compatible behavior).

Accordion Group (Mutual Exclusion)

Wrap multiple accordion items in an accordion-group to ensure only one can be open at a time:

<accordion-group>
  <accordion-item open>
    <button slot="trigger-container">First Item</button>
    <div>Only one item can be open at a time</div>
  </accordion-item>

  <accordion-item>
    <button slot="trigger-container">Second Item</button>
    <div>Opening this will close the first</div>
  </accordion-item>

  <accordion-item>
    <button slot="trigger-container">Third Item</button>
    <div>Same behavior here</div>
  </accordion-item>
</accordion-group>

Custom Animation

<accordion-item animation-time="500" animation-easing="ease-in-out">
  <button slot="trigger-container">Slow animation</button>
  <div>This opens and closes slower</div>
</accordion-item>

Programmatic Control

const accordion = document.querySelector('accordion-item');

// Open the accordion
accordion.show();

// Close the accordion
accordion.close();

// Toggle open/closed state
accordion.toggle();

// Listen to events
accordion.addEventListener('accordion-opened', (e) => {
  console.log('Opened!', e.detail);
});

accordion.addEventListener('accordion-closed', (e) => {
  console.log('Closed!', e.detail);
});

API

<accordion-item>

Attributes

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | open | boolean | false | When present, the accordion starts in an expanded state | | animation-time | string | "300" | Animation duration in milliseconds | | animation-easing | string | "ease" | CSS easing function (e.g., ease-in-out, cubic-bezier(...)) |

Slots

| Slot | Description | |------|-------------| | trigger-container | Container for the trigger element(s). Use accordion-trigger attribute to specify which element toggles the accordion | | (default) | The accordion content |

Methods

| Method | Description | |--------|-------------| | show() | Opens the accordion | | close() | Closes the accordion | | toggle() | Toggles between open and closed states |

Events

| Event | Detail | Description | |-------|--------|-------------| | accordion-opened | { open: true } | Dispatched when the accordion opens | | accordion-closed | { open: false } | Dispatched when the accordion closes |

<accordion-group>

Attributes

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | allow-multiple-open | boolean | false | When present, allows multiple accordions to be open simultaneously |

Styling

Styling the Open State

Use the [open] attribute selector to style accordion items when expanded:

/* Rotate chevron icon when accordion is open */
accordion-item[open] [slot="trigger-container"] svg {
  transform: rotate(180deg);
}

/* Change background color when open */
accordion-item[open] [slot="trigger-container"] {
  background-color: #f1f5f9;
}

/* Add border accent when open */
accordion-item[open] {
  border-left: 4px solid #3b82f6;
}

Accessibility

This component includes built-in accessibility features:

  • Automatic aria-expanded attribute on trigger elements
  • Keyboard support (Enter/Space) for non-button triggers
  • Automatic role="button" for non-button triggers
  • Screen reader friendly state announcements

Browser Support

Works in all modern browsers that support:

  • Custom Elements v1
  • Shadow DOM v1
  • ES Modules

License

MIT

Author

Joel Geering