Skip to content
A modal dialog that's opened with <details>.
JavaScript TypeScript HTML CSS
Branch: master
Clone or download

Latest commit

Latest commit f3f0a59 Jun 10, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Pull shadow dom demo code out May 4, 2020
src Fix getRootNode not available in Edge 18 Jun 9, 2020
test Add test in Shadow DOM context May 4, 2020
.eslintrc.json Add new line at EOF May 6, 2020
.gitignore Treat dist as build output directory Apr 3, 2018
.travis.yml Fix Travis headless Chrome runner Apr 4, 2018
LICENSE Add example usage Mar 29, 2018
README.md Add script tag usage May 6, 2020
package-lock.json 3.1.1 Jun 10, 2020
package.json 3.1.1 Jun 10, 2020
tsconfig.json Convert to TypeScript and modernize build May 4, 2020

README.md

<details-dialog> element

A modal dialog that's opened with a <details> button.

Installation

$ npm install --save @github/details-dialog-element

Usage

Script

Import as ES modules:

import '@github/details-dialog-element'

Include with a script tag:

<script type="module" src="./node_modules/@github/details-dialog-element/dist/index.js">

Markup

<details>
  <summary>Open dialog</summary>
  <details-dialog>
    Modal content
    <button type="button" data-close-dialog>Close</button>
  </details-dialog>
</details>

Deferred loading

Dialog content can be loaded from a server by embedding an <include-fragment> element.

<details>
  <summary>Robots</summary>
  <details-dialog src="/robots" preload>
    <include-fragment>Loading…</include-fragment>
  </details-dialog>
</details>

The src attribute value is copied to the <include-fragment> the first time the <details> button is toggled open, which starts the server fetch.

If the preload attribute is present, hovering over the <details> element will trigger the server fetch.

Events

details-dialog-close

details-dialog-close event is fired from <details-dialog> when a request to close the dialog is made from

  • pressing escape,
  • clicking on summary, [data-close-dialog], or
  • dialog.toggle(false)

This event bubbles, and can be canceled to keep the dialog open.

document.addEventListener('details-dialog-close', function(event) {
  if (!confirm('Are you sure?')) {
    event.preventDefault()
  }
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

You can’t perform that action at this time.