{"id":21995331,"url":"https://github.com/polymerlabs/blocking-elements","last_synced_at":"2025-08-24T01:11:37.744Z","repository":{"id":11022583,"uuid":"63896712","full_name":"PolymerLabs/blocking-elements","owner":"PolymerLabs","description":"Expose a stack of blocking elements https://github.com/whatwg/html/issues/897","archived":false,"fork":false,"pushed_at":"2023-10-19T17:55:27.000Z","size":1565,"stargazers_count":15,"open_issues_count":17,"forks_count":4,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-04-11T00:19:42.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PolymerLabs.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":"2016-07-21T19:26:30.000Z","updated_at":"2024-06-18T16:51:59.823Z","dependencies_parsed_at":"2024-06-18T16:51:40.155Z","dependency_job_id":"9a8ada23-4f88-49ea-b695-9bd2cd83461e","html_url":"https://github.com/PolymerLabs/blocking-elements","commit_stats":{"total_commits":56,"total_committers":4,"mean_commits":14.0,"dds":0.4107142857142857,"last_synced_commit":"af46699b5f3094e851d3678448a7b31f01f6834e"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerLabs%2Fblocking-elements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerLabs%2Fblocking-elements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerLabs%2Fblocking-elements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolymerLabs%2Fblocking-elements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PolymerLabs","download_url":"https://codeload.github.com/PolymerLabs/blocking-elements/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251750607,"owners_count":21637751,"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":[],"created_at":"2024-11-29T21:14:16.934Z","updated_at":"2025-04-30T17:27:38.478Z","avatar_url":"https://github.com/PolymerLabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/PolymerLabs/blocking-elements.svg?branch=master)](https://travis-ci.org/PolymerLabs/blocking-elements)\n[![Published on npm](https://img.shields.io/npm/v/blocking-elements.svg)](https://www.npmjs.com/package/blocking-elements)\n\n# Blocking Elements stack API\n\nImplementation of proposal https://github.com/whatwg/html/issues/897\n\n\u003e The polyfill chooses a non-colliding name (`document.$blockingElements` instead of `document.blockingElements`) as the proposal is still work in progress and hasn't yet reached consensus on the semantics and functionality (see [this discussion](https://github.com/PolymerLabs/blocking-elements/pull/1#issuecomment-235102344) for more details).\n\n`document.$blockingElements` manages a stack of elements that inert the interaction outside them.\n\n- the stack can be updated with the methods `push(elem), remove(elem), pop()`\n- the top element (`document.$blockingElements.top`) and its subtree is the interactive part of the document\n- `has(elem)` returns if the element is a blocking element\n\nThis polyfill will:\n\n- search for the path of the element to block up to `document.body`\n- set `inert` to all the siblings of each parent, skipping the parents and the element's distributed content (if any)\n\nUse this polyfill together with the [wicg-inert](https://github.com/WICG/inert) polyfill to disable interactions on the rest of the document. See the [demo page](https://github.com/PolymerLabs/blocking-elements/blob/master/demo/index.html) as an example.\n\n## Why not listening to events that trigger focus change?\n\nAnother approach could be to listen for events that trigger focus change (e.g. `focus, blur, keydown`) and prevent those if focus moves out of the blocking element.\n\nWrapping the focus requires to find all the focusable nodes within the top blocking element, eventually sort by tabindex, in order to find first and last focusable node.\n\nThis approach doesn't allow the focus to move outside the window (e.g. to the browser's url bar, dev console if opened, etc.), and is less robust when used with assistive technology (e.g. android talkback allows to move focus with swipe on screen, Apple Voiceover allows to move focus with special keyboard combinations).\n\n## Install \u0026 use\n\nBlocking Elements relies on the [`inert` attribute](https://github.com/WICG/inert) and uses [`Set` objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set), so make sure to include their polyfills as needed.\n\n```bash\nnpm install --save babel-polyfill\nnpm install --save wicg-inert\nnpm install --save blocking-elements\n```\n\n```html\n\u003cscript src=\"./node_modules/babel-polyfill/dist/polyfill.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/wicg-inert/dist/inert.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/blocking-elements/dist/blocking-elements.min.js\"\u003e\u003c/script\u003e\n\n\u003cdiv id=\"container\"\u003e\n  \u003cbutton onclick=\"makeBlocking(container)\"\u003emake blocking\u003c/button\u003e\n  \u003cbutton onclick=\"undoBlocking(container)\"\u003eundo blocking\u003c/button\u003e\n\u003c/div\u003e\n\n\u003cbutton\u003esome button\u003c/button\u003e\n\n\u003cscript\u003e\n  function makeBlocking(element) {\n    document.$blockingElements.push(element);\n  }\n  function undoBlocking(element) {\n    document.$blockingElements.remove(element);\n  }\n\u003c/script\u003e\n```\n\n## Files\n\nTwo scripts are included:\n\n1. `/dist/blocking-elements.min.js`: minified and transpiled to ES5.\n\n2. `/dist/blocking-elements.js`: un-minified ES2017.\n\n   If your toolchain supports Node-style module resolution (e.g. TypeScript's `--moduleResolution=node`), then the main `blocking-elements` bare module specifier resolves to this file. TypeScript declarations are also included for this module:\n   \n   ```ts\n   import {DocumentWithBlockingElements} from 'blocking-elements';\n\n   const blockingElements =\n       (document as DocumentWithBlockingElements).$blockingElements;\n\n   blockingElements.push(...);\n   blockingElements.remove(...);\n   ```\n\n\n## Local development\n\nInstall the dependencies with `npm install` and serve the resources.\n\nRun the tests locally by navigating to http://localhost:8080/test/\n\n## Performance\n\nPerformance is dependent on the `inert` polyfill performance. Chrome recently landed [the `inert` attribute implementation](https://codereview.chromium.org/2088453002/) behind a flag.\n\nLet's compare the how long it takes to toggle the deepest `x-trap-focus` inside nested `x-b` of the demo page (\u003chttp://localhost:8080/demo/ce.html?ce=v1\u003e)\n\n![results](https://cloud.githubusercontent.com/assets/6173664/17538133/914f365a-5e57-11e6-9b91-1c6b7eb22d57.png).\n\n`document.$blockingElements` with native inert is **~15x faster** than polyfilled inert 🎉 🎉 🎉\n\n| with polyfilled inert (M58) | with native inert (M60) |\n|----------|--------|\n| ![polyfill-inert-1.png](assets/polyfill-inert-1.png) | ![native-inert-1.png](assets/native-inert-1.png) |\n| ![polyfill-inert-2.png](assets/polyfill-inert-2.png) | ![native-inert-2.png](assets/native-inert-2.png) |\n| ![polyfill-inert-3.png](assets/polyfill-inert-3.png) | ![native-inert-3.png](assets/native-inert-3.png) |\n| ![polyfill-inert-4.png](assets/polyfill-inert-4.png) | ![native-inert-4.png](assets/native-inert-4.png) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymerlabs%2Fblocking-elements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolymerlabs%2Fblocking-elements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymerlabs%2Fblocking-elements/lists"}