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

v0.2.7

Published

Headless modal dialog component for vanilla JavaScript. Accessible, unstyled, tiny.

Readme

@data-slot/dialog

Headless modal dialog component for vanilla JavaScript. Accessible, unstyled, tiny.

Installation

npm install @data-slot/dialog

Quick Start

<div data-slot="dialog">
  <button data-slot="dialog-trigger">Open Dialog</button>
  <div data-slot="dialog-content" hidden>
    <h2 data-slot="dialog-title">Dialog Title</h2>
    <p data-slot="dialog-description">Dialog description text.</p>
    <button data-slot="dialog-close">Close</button>
  </div>
</div>

<script type="module">
  import { create } from "@data-slot/dialog";
  
  const controllers = create();
</script>

API

create(scope?)

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

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

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

createDialog(root, options?)

Create a controller for a specific element.

import { createDialog } from "@data-slot/dialog";

const dialog = createDialog(element, {
  defaultOpen: false,
  closeOnClickOutside: true,
  closeOnEscape: true,
  lockScroll: true,
  onOpenChange: (open) => console.log(open),
});

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | defaultOpen | boolean | false | Initial open state | | closeOnClickOutside | boolean | true | Close when clicking outside content | | closeOnEscape | boolean | true | Close when pressing Escape | | lockScroll | boolean | true | Lock body scroll when open | | alertDialog | boolean | false | Use alertdialog role for confirmations | | onOpenChange | (open: boolean) => void | undefined | Callback when open state changes |

Data Attributes

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

| Attribute | Type | Default | Description | |-----------|------|---------|-------------| | data-default-open | boolean | false | Initial open state | | data-close-on-click-outside | boolean | true | Close when clicking outside content | | data-close-on-escape | boolean | true | Close when pressing Escape | | data-lock-scroll | boolean | true | Lock body scroll when open | | data-alert-dialog | boolean | false | Use alertdialog role for confirmations |

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

<!-- Disable close on Escape -->
<div data-slot="dialog" data-close-on-escape="false">
  ...
</div>

<!-- Alert dialog that stays open when clicking outside -->
<div data-slot="dialog" data-alert-dialog data-close-on-click-outside="false">
  ...
</div>

Controller

| Method/Property | Description | |-----------------|-------------| | open() | Open the dialog | | close() | Close the dialog | | toggle() | Toggle the dialog | | isOpen | Current open state (readonly boolean) | | destroy() | Cleanup all event listeners |

Markup Structure

<div data-slot="dialog">
  <button data-slot="dialog-trigger">Open</button>
  <div data-slot="dialog-content" role="dialog">
    <h2 data-slot="dialog-title">Title</h2>
    <p data-slot="dialog-description">Description</p>
    <button data-slot="dialog-close">Close</button>
  </div>
</div>

Required Slots

  • dialog-content - The dialog panel (required)

Optional Slots

  • dialog-trigger - Button to open the dialog
  • dialog-title - Title for aria-labelledby
  • dialog-description - Description for aria-describedby
  • dialog-close - Button to close the dialog

Styling

Use data-state attributes for CSS styling:

/* Backdrop/overlay */
[data-slot="dialog-content"] {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
}

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

/* Animation */
[data-slot="dialog-content"] {
  opacity: 0;
  transition: opacity 0.2s;
}

[data-slot="dialog"][data-state="open"] [data-slot="dialog-content"] {
  opacity: 1;
}

With Tailwind:

<div data-slot="dialog-content" class="fixed inset-0 grid place-items-center bg-black/50 data-[state=closed]:hidden">
  <div class="bg-white rounded-lg p-6 max-w-md">
    <!-- Dialog content -->
  </div>
</div>

Accessibility

The component automatically handles:

  • role="dialog" on content
  • aria-modal="true" on content
  • aria-labelledby linked to title
  • aria-describedby linked to description
  • aria-haspopup="dialog" on trigger
  • aria-expanded state on trigger
  • Focus trap within dialog
  • Focus restoration on close

Keyboard Navigation

| Key | Action | |-----|--------| | Escape | Close dialog | | Tab | Cycle focus within dialog | | Shift+Tab | Cycle focus backwards |

Events

Listen for changes via custom events:

element.addEventListener("dialog:change", (e) => {
  console.log("Dialog open:", e.detail.open);
});

License

MIT