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

@rynpsc/dialog

v5.0.2

Published

A modern, lightweight and accessible dialog with a focus on progressive enhancement

Readme

Dialog

Dialog provides a bare bones baseline for building accessible modals or modal like UI elements such as fullscreen menus.

npm version npm bundle size (minified and gzipped)

Features

  • Takes care of adding the correct aria roles and attributes.
  • Sends and traps focus within the dialog.
  • Provides an event API via CustomEvents.
  • Simple data attribute API for opening and closing.

View demo on CodePen

Install

$ npm install @rynpsc/dialog

Usage

The dialog constructor takes two parameters:

  • id - The ID of the element used as the dialog
  • options - Configuration Object (see options)

HTML

<body>
  
  <header></header>
  <main></main>
  <footer></footer>

  <div class="dialog" id="my-dialog">
    <!-- Dialog content -->
  </div>

</body>

JavaScript

import { dialog } from '@rynpsc/dialog';

const dialog = dialog('my-dialog', options);

if (dialog) {
  dialog.create();
}

CSS

.dialog {
  visibility: hidden;
}

.dialog.is-open {
  visibility: visible;
}

For an example on how to animate the dialog see the CodePen demo.

## Options

```js
{
  // ID of HTMLElement to use in aria-labelledby or a string to use as the aria-label.
  label: 'Dialog',
  
  // ID of HTMLElement to use in aria-describedby.
  description: '',
  
  // Set dialog role to alertdialog.
  alert: false,

  // Enable automatic focus management.
  manageFocus: true,

  // The class applied to elements.dialog when open.
  openClass: 'is-open'
}

API

dialog(id: string, options: Object)

Creates a dialog instance.

.open(element: HTMLElement | undefined | null = undefined, scroll: boolean = true)

Open the dialog.

The optional element argument can be used to control the element that gets focused on opening. If undefined (the default) the first focusalbe element will be focused or the first element with the data-dialog-autofocus attribute. If null is passed, focus will not be redirected.

dialog.open(element);

.close(element: HTMLElement | undefined | null = undefined, scroll: boolean = true)

Close the dialog.

The optional element argument can be used to control the element that gets focused on closing. If not set (undefined) the element that had focus before calling open will be focused. If null is passed, focus will not be redirected.

dialog.close();

.toggle(force: boolean)

Toggle the dialog between opened and closed.

dialog.toggle();

If the optional force parameter evaluates to true, open the dialog, if false, close the dialog.

.create()

Create the dialog after destroying it.

dialog.create();

.destroy()

Destroy the dialog.

dialog.destroy();

.on(string, function)

Subscribe to an event.

dialog.on(event);

.off(string, function)

Unsubscribe to an event.

dialog.off(event);

.isOpen

Returns a boolean indicating if the dialog is currently open.

dialog.isOpen;

.initiated

Returns a boolean indicating if the dialog has been initiated.

dialog.isOpen;

.id

The ID that was passed into the constructor.

dialog.id

.element

The HTMLElement matching the ID passed into the constructor.

dialog.element

instances

Returns an object of all the dialog instances.

import { instances } from '@rynpsc/dialog';

console.table(instances);

getInstanceById(string)

Gets a dialog instance with the given id.

import { getInstanceById } from '@rynpsc/dialog';

const instance = getInstanceById('dialog');

if (instance) {
  instance.open();
}

Data Attribute API

This library contains an optional data attribute API that enables opening and closing a dialog instance.

import { domapi } from '@rynpsc/dialog';

domapi.mount()

<div id="dialog">
  <!-- Dialog content -->
</div>

<button data-dialog-open="dialog">Open Dialog</button>
<button data-dialog-close="dialog">Close Dialog</button>

Where "dialog" is the ID of the dialog element.

.mount()

Get and add event listeners to elements with data attributes.

domapi.mount();

.unmount()

Remove event listeners from elements.

domapi.unmount();

.openers

Get elements that will trigger open.

domapi.openers;

.closers

Get elements that will trigger close.

domapi.closers;

Events

Events are handled via the CustomEvent API.

open

Emitted when the dialog opens.

dialog.on('open', handler);

This event can be cancelled, see Cancelling events.

close

Emitted when the dialog closes.

dialog.on('close', handler);

This event can be cancelled, see Cancelling events.

create

dialog.on('create', handler);

Emitted after the dialog is created.

destroy

dialog.on('destroy', handler);

Emitted after the dialog is destroyed.

Cancelling events

The open and close events can be canceled by calling event.preventDefault in the event handler.

dialog.on('close', function(event) {
  event.preventDefault();
});

Browser Support

Requires the following API's:

  • Array.from
  • Array.prototype.filter
  • Array.prototype.some
  • CustomEvent
  • DOMTokenList.contains
  • Element.classList
  • Element.matches
  • Element.querySelectorAll
  • HTMLElement.dataset

License

MIT