зеркало из
1
0
Форкнуть 0
A modal dialog that's opened with
.
Перейти к файлу
Manuel Puyol df1df8d233
Merge pull request #92 from github/depreciate-this-component
Add depreciated note to README
2022-09-21 12:15:59 -05:00
.devcontainer Add a .devcontainer 2022-02-28 17:04:16 +00:00
.github/workflows Create .github/workflows/publish.yml 2022-03-25 19:21:00 +00:00
example Remaining useless `<form>` element in exemple 2021-03-08 13:59:23 -05:00
src Merge branch 'main' into trap-focus-when-connected-as-open 2022-08-15 09:29:18 -05:00
test Trap focus when connected in `<details open>` 2022-08-09 15:47:09 -04:00
.eslintrc.json Add new line at EOF 2020-05-06 14:26:56 -04:00
.gitignore Treat dist as build output directory 2018-04-03 12:28:22 -06:00
CODEOWNERS Create CODEOWNERS 2021-09-13 15:01:58 +01:00
LICENSE Add example usage 2018-03-29 15:26:32 -06:00
README.md deprecated not depreciated 2022-09-21 18:12:16 +01:00
custom-elements-manifest.config.js Use `@github/cem-plugin-readme` instead of inlined version 2022-08-15 11:02:16 +02:00
custom-elements.json Add README plugin and generate README 2022-08-12 11:05:34 +02:00
package-lock.json Install `@github/cem-plugin-readme` 2022-08-15 11:01:08 +02:00
package.json Include CEM files in npm package 2022-08-15 11:40:54 +02:00
tsconfig.json Convert to TypeScript and modernize build 2020-05-04 15:24:29 -04:00
vscode.html-custom-data.json Add README plugin and generate README 2022-08-12 11:05:34 +02:00

README.md

<details-dialog> element

A modal dialog opened with a <details> button.

DEPRECATION WARNING

This web component has been deprecated. There are a number of accessibility concerns with this approach and so we no longer recommend using this component.

Accessibility and Usability Concerns

  • Semantically, using a details-summary pattern for a dialog solution can be confusing for screen reader users.
  • If the user performs a "find in page" operation on a website using details-dialog elements, the content on those elements will appear when they shouldn't.
  • Opening the dialog does not disable scrolling on the underlying page.

GitHub are moving towards using a dialog Primer View Component which enforces certain aspects of the design (such as always having a close button and a title).

Installation

Available on npm as @github/details-dialog-element.

$ 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>][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,
  • submitting a form[method="dialog"]
  • clicking on summary, form button[formmethod="dialog"], [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

License

Distributed under the MIT license. See LICENSE for details.