{"id":13517144,"url":"https://github.com/GoogleChrome/dialog-polyfill","last_synced_at":"2025-03-31T07:31:03.275Z","repository":{"id":9719084,"uuid":"11674840","full_name":"GoogleChrome/dialog-polyfill","owner":"GoogleChrome","description":"Polyfill for the HTML dialog element","archived":false,"fork":false,"pushed_at":"2024-09-26T22:15:26.000Z","size":373,"stargazers_count":2450,"open_issues_count":32,"forks_count":241,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-03-25T19:05:23.197Z","etag":null,"topics":["a11y","dialog","html","polyfill"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleChrome.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-26T01:17:35.000Z","updated_at":"2025-03-10T12:22:43.000Z","dependencies_parsed_at":"2022-07-12T15:03:41.170Z","dependency_job_id":"8cd08862-9a76-440e-8a6d-ba12ebce7be4","html_url":"https://github.com/GoogleChrome/dialog-polyfill","commit_stats":{"total_commits":256,"total_committers":47,"mean_commits":5.446808510638298,"dds":0.4375,"last_synced_commit":"5033aac1b74c44f36cde47be3d11f4756f3f8fda"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fdialog-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fdialog-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fdialog-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fdialog-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleChrome","download_url":"https://codeload.github.com/GoogleChrome/dialog-polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246433093,"owners_count":20776527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a11y","dialog","html","polyfill"],"created_at":"2024-08-01T05:01:30.372Z","updated_at":"2025-03-31T07:31:02.911Z","avatar_url":"https://github.com/GoogleChrome.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"dialog-polyfill.js is a polyfill for `\u003cdialog\u003e` and `\u003cform method=\"dialog\"\u003e`.\nCheck out [some demos](https://googlechrome.github.io/dialog-polyfill/)!\n\n`\u003cdialog\u003e` is an element for a popup box in a web page, including a modal option which will make the rest of the page inert during use.\nThis could be useful to block a user's interaction until they give you a response, or to confirm an action.\nSee the [HTML spec](https://html.spec.whatwg.org/multipage/forms.html#the-dialog-element).\n\n## Usage\n\n### Installation\n\nYou may optionally install via NPM -\n\n    $ npm install dialog-polyfill\n\n\nThere are several ways that to include the dialog polyfill:\n\n* include `dist/dialog-polyfill.js` script directly in your HTML, which exposes a global `dialogPolyfill` function.\n* `import` (es modules)\n* `require` (commonjs/node)\n\n\n```javascript\n// direct import (script module, deno)\nimport dialogPolyfill from './node_modules/dialog-polyfill/dist/dialog-polyfill.esm.js';\n\n// *OR*\n\n// modern es modules with rollup/webpack bundlers, and node via esm module\nimport dialogPolyfill from 'dialog-polyfill'\n\n// *OR*\n\n// traditional commonjs/node and browserify bundler\nconst dialogPolyfill = require('dialog-polyfill')\n```\n\n\n### Supports\n\nThis polyfill works on modern versions of all major browsers.\nIt also supports IE9 and above.\nIt can work when used inside Shadow DOM, but it's not recommended.\n\n### Steps\n\n1. Include the CSS in the `\u003chead\u003e` of your document, and the JS anywhere before referencing `dialogPolyfill`.\n2. Create your dialog elements within the document. See [limitations](#limitations) for more details.\n3. Register the elements using `dialogPolyfill.registerDialog()`, passing it one node at a time. This polyfill won't replace native support.\n4. Use your `\u003cdialog\u003e` elements!\n\n## Script Global Example\n\n```html\n\u003chead\u003e\n  \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"dist/dialog-polyfill.css\" /\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cdialog\u003e\n    I'm a dialog!\n    \u003cform method=\"dialog\"\u003e\n      \u003cinput type=\"submit\" value=\"Close\" /\u003e\n    \u003c/form\u003e\n  \u003c/dialog\u003e\n  \u003cscript src=\"dist/dialog-polyfill.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    var dialog = document.querySelector('dialog');\n    dialogPolyfill.registerDialog(dialog);\n    // Now dialog always acts like a native \u003cdialog\u003e.\n    dialog.showModal();\n  \u003c/script\u003e\n\u003c/body\u003e\n```\n\n### ::backdrop\n\nIn native `\u003cdialog\u003e`, the backdrop is a pseudo-element.\nWhen using the polyfill, the backdrop will be an adjacent element:\n\n```css\ndialog::backdrop { /* native */\n  background-color: green;\n}\ndialog + .backdrop { /* polyfill */\n  background-color: green;\n}\n```\n\n## Limitations\n\nIn the polyfill, modal dialogs have limitations-\n\n- They should not be contained by parents that create a stacking context, see below\n- The browser's chrome may not always be accessible via the tab key\n- Changes to the CSS top/bottom values while open aren't retained\n\n### Stacking Context\n\nThe major limitation of the polyfill is that dialogs should not have parents that create [a stacking context](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context).\nThe easiest way to solve this is to move your `\u003cdialog\u003e` element to be a child of `\u003cbody\u003e`.\n\nIf this isn't possible you may still be able to use the dialog.\nHowever, you may want to resolve it for two major reasons-\n\n1. The polyfill can't guarantee that the dialog will be the top-most element of your page\n2. The dialog may be positioned incorrectly as they are positioned as part of the page layout _where they are opened_ (defined by spec), and not at a fixed position in the user's browser.\n\nTo position a dialog in the center (regardless of user scroll position or stacking context), you can specify the following CSS-\n\n```css\ndialog {\n  position: fixed;\n  top: 50%;\n  transform: translate(0, -50%);\n}\n```\n\nThis is also provided as a helper CSS class in the polyfill CSS, `.fixed`.\nYou can apply by using HTML like `\u003cdialog class=\"fixed\"\u003e`.\n\n## Extensions\n\n### Focus\n\nThe WAI-ARIA doc suggests returning focus to the previously focused element after a modal dialog is closed.\nHowever, this is not part of the dialog spec itself.\nSee [this snippet](https://gist.github.com/samthor/babe9fad4a65625b301ba482dad284d1) to add this, even to the native `dialog`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChrome%2Fdialog-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleChrome%2Fdialog-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChrome%2Fdialog-polyfill/lists"}