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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@webfactoryde/dialog-utils

v0.2.0

Published

Web Component with progressive enhancements for the HTML <dialog> element

Readme

<dialog-utils>

Web Component with progressive enhancements for the HTML <dialog> element

Installation

npm install @webfactoryde/dialog-utils

Usage

The <dialog-utils> Web Component is meant to be a lightweight wrapper and progressive enhancement for <dialog> elements that are used as modal dialogs.

The enhancements are:

  1. autoopen: The Web Component supports opening a dialog immediately if an autoopen attribute is present on <dialog-utils>.
  2. commandfor and command: The Web Component polyfills the Invoker Commands API to enable future-friendly, declarative linkup of buttons to show and close the dialog even in browsers that don't support the API yet. You can opt out of this if you prefer to write your own JavaScript logic to handle this functionality.
  3. closedby="any": The Web Component polyfills the declarative attribute for light dismissal of the dialog by a click outside of it.
  4. Playing media: If the dialog contains an iframe, the Web Component will ensure that any media stops playing when the dialog is closed.
  5. Focus behaviour: You should use the declarative autofocus attribute to indicate whether the dialog itself or a specific interactive child element should receive focus when the dialog is shown. If this is not an option, the Web Component accepts a autofocus-target attribute with a valid DOM selector string as its value. The WC will then try to set the autofocus attribute on the first element that matches the selector.
  6. Page scroll: If the dialog is opened as a modal, scrolling is disabled on the <body> and re-enabled on close.
  7. The Web Component emits a custom open event when the dialog is opened.

Steps to implement:

  1. The JS file "dialog-utils.js" must be loaded. Depending on browser support requirements, transpilation for older browsers is recommended.
  2. Wrap your <dialog> with <dialog-utils>.
  3. Add a trigger and close <button> with your desired markup (e.g. nested icon, attributes, translated text, etc.). The buttons need to be made identifiable with commandfor and command as per the specification, if you want to benefit from the ease-of-use polyfills. The Web Component leaves positioning and aesthetics of the buttons to the outside context.

Basic example

<button commandfor="my-dialog" command="show-modal">Open my dialog</button>

<dialog-utils>
    <dialog id="my-dialog>
        <button commandfor="my-dialog" command="close">Close</button>
        <h1>My modal</h1>
        <p>Some content</p>
    </dialog>
</dialog-utils>

Events

open

The component emits a open event on the <dialog> element that includes information about whether the dialog is displayed as a modal via (bool) event.detail.isModal.

Caveat: This requires support for the toggle event which is Baseline 2023 but with a known regression for dialog in Safari 18 (fixed in Safari 26).

Extending the component

The component is exported to allow subclassing and extending its methods.

Example

import {DialogUtils} from '@webfactoryde/dialog-utils';

class MyCustomDialogUtils extends DialogUtils {
    onOpen(event) {
        // call the parent method
        super.onOpen?.(event);

        // do your custom thing
    }
}

customElements.define('my-custom-dialog-utils', MyCustomDialogUtils);