зеркало из
1
0
Форкнуть 0
A modal dialog that's opened with
.
Перейти к файлу
Mu-An 慕安 7522db203a
Merge pull request #32 from github/open-focus
Fix autofocusing when details is not open & preload toggling
2019-04-09 12:17:14 -04:00
test Update event name and docs 2019-03-14 17:13:03 -04:00
.babelrc use babel-preset-github 2019-02-25 12:26:51 +00:00
.eslintrc.json inline test eslint config in root eslint config 2019-02-25 12:31:32 +00:00
.flowconfig Set up Flow 2018-08-09 20:20:03 -04:00
.gitignore Treat dist as build output directory 2018-04-03 12:28:22 -06:00
.travis.yml Fix Travis headless Chrome runner 2018-04-04 17:54:52 -06:00
LICENSE Add example usage 2018-03-29 15:26:32 -06:00
README.md Merge branch 'event' 2019-04-05 17:10:28 -04:00
content.html Make example page work 2019-04-03 16:26:18 -04:00
index.css Add max width set to 90vw 2018-07-20 10:29:11 -07:00
index.html Make example page work 2019-04-03 16:26:18 -04:00
index.js Fix removing preload does not remove event listener when src is present 2019-04-08 16:28:44 -04:00
index.js.flow Set up Flow 2018-08-09 20:20:03 -04:00
package-lock.json 3.0.0 2019-04-05 17:11:43 -04:00
package.json 3.0.0 2019-04-05 17:11:43 -04:00
prettier.config.js Initial commit 2017-11-24 15:47:45 +08:00

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.