Skip to content
A modal dialog that's opened with <details>.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.babelrc use babel-preset-github Feb 25, 2019
.eslintrc.json inline test eslint config in root eslint config Feb 25, 2019
.flowconfig Set up Flow Aug 10, 2018
.gitignore
.travis.yml Fix Travis headless Chrome runner Apr 4, 2018
LICENSE Add example usage Mar 29, 2018
README.md Merge branch 'event' Apr 5, 2019
content.html Make example page work Apr 3, 2019
index.css Add max width set to 90vw Jul 20, 2018
index.html Label everything May 2, 2019
index.js Add aria-modal="true" May 1, 2019
index.js.flow
package-lock.json 3.0.2 May 2, 2019
package.json 3.0.2 May 2, 2019
prettier.config.js Initial commit Nov 24, 2017

README.md

<details-dialog> element

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

Installation

$ npm install --save details-dialog-element

Usage

import 'details-dialog-element'
<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.