Polyfill for the HTML dialog element
Перейти к файлу
Sam Thorogood 29b088d4ed focus on show() as well as showModal() 2016-03-22 12:03:03 +11:00
tests remove -webkit- hack 2016-02-02 08:58:11 +11:00
.gitignore gitignore 2015-06-06 15:21:36 +10:00
LICENSE Initial commit 2013-07-26 10:29:52 +09:00
README.md Merge pull request #86 from karlhorky/add-demo-and-modal-note 2016-03-11 16:52:58 +00:00
bower.json basic mocha/chai test suites 2015-06-06 15:21:10 +10:00
dialog-polyfill.css don't allow clicks on overlay; backdrop appears as dialog 2015-06-07 17:50:10 +10:00
dialog-polyfill.js focus on show() as well as showModal() 2016-03-22 12:03:03 +11:00
package.json npm release 0.4.3 2016-02-12 19:48:32 +11:00
suite.js focus on show() as well as showModal() 2016-03-22 12:03:03 +11:00
test.html basic mocha/chai test suites 2015-06-06 15:21:10 +10:00

README.md

dialog-polyfill.js is a polyfill for <dialog>.

Demo

<dialog> is an element for a popup box in a web page, including a modal option. See more information and demos and the HTML spec.

Usage

Installation

You may optionally install via NPM or Bower-

$ npm install dialog-polyfill
$ bower install dialog-polyfill

Supports

This polyfill works on modern versions of all major browsers. It also supports IE9 and above.

Steps

  1. Include the JavaScript, followed by the CSS in the <head> of your document.
  2. Create your dialog elements within the document. See limitations for more details.
  3. Register the elements using dialogPolyfill.registerDialog(), passing it one node at a time. This polyfill won't replace native support.
  4. Use your <dialog> elements!

Example

<head>
  <script src="dialog-polyfill.js"></script>
  <link rel="stylesheet" type="text/css" href="dialog-polyfill.css" />
</head>
<body>
  <dialog>
    I'm a dialog!
    <form method="dialog">
      <input type="submit" value="Close" />
    </form>
  </dialog>
  <script>
    var dialog = document.querySelector('dialog');
    dialogPolyfill.registerDialog(dialog);
    // Now dialog acts like a native <dialog>.
    dialog.showModal();
  </script>
</body>

::backdrop

In native <dialog>, the backdrop is a pseudo-element:

#mydialog::backdrop {
  background-color: green;
}

When using the polyfill, the backdrop will be an adjacent element:

#mydialog + .backdrop {
  background-color: green;
}

#mydialog::backdrop {
  background-color: green;
}

Limitations

  • Modal dialogs have limitations-

    • They should be a child of <body> or have parents without layout (aka, no position absolute or relative elements)
    • The browser's chrome may not be accessible via the tab key
    • Stacking can be ruined by playing with z-index
    • Changes to the CSS top/bottom values while open aren't retained
  • Anchored positioning is not implemented, but the native <dialog> in Chrome doesn't have it either