• This repository has been archived on 30/Dec/2022
  • Stars
    star
    188
  • Rank 198,137 (Top 5 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Polyfill for the HTML inert attribute

Polyfill for the inert HTML attribute. Check out a small demo.

The inert attribute is a draft feature of HTML. As of Feb 2017, no browser has a native implementation of inert. However, there is active development inside Chrome, and other browsers have shown some renewed interest.

From the HTML spec-

A node (in particular elements and text nodes) can be marked as inert. When a node is inert, then the user agent must act as if the node was absent for the purposes of targeting user interaction events, may ignore the node for the purposes of text search user interfaces (commonly known as "find in page"), and may prevent the user from selecting text in that node.

While not a replacement for proper state management, web developers can use the inert attribute to prevent access to subtrees. This could be useful to prevent access to active HTML forms, to enable modal-like popovers, or to block user interaction while awaiting the result of an asynchronous operation.

Example

<div inert>
  <button>I'm unclickable!</button>
  <input type="text" placeholder="I'm unfocusable!" />
</div>

Usage

Include the inert-polyfill script at the end of your page. There are no other initialization steps.

The polyfill prevents tab-focusing, using the accessKey to access an element, the click event (mostly for sanity, as elements should be unfocusable), and any other approach to focus.

Installation

You may optionally install via NPM or Bower-

$ npm install inert-polyfill
$ bower install inert-polyfill

Supports

This polyfill works on modern versions of all major browsers. It also supports IE9 and above, although links and buttons may appear clickable (IE9 and IE10 do not support pointer-events, although there is a polyfill).

Limitations

Most limitations revolve around keyboard access and the tab key-

  • Most browsers don't support emulating tab events, so positive values of tabIndex may be ignored
    • Avoid relying on a specific tab order
  • Inert elements at the very start or end of a page may prevent tab access to the browser's chrome
  • While tabbing over inert elements, inner elements may still receive intermediate focus and blur events

Other limitations include-

  • Content within an inert element may still be searched for (using the browser's Find box) or selected
  • Focused elements that become inert due to surrounding HTML changes will remain focused
  • Inert will work within a shadow root, but the CSS to support it is not included

If these limitations do not work for your project, there is also a WICG polyfill, which uses MutationObserver to recursively walk HTML trees to clear tabIndex (clearing or setting to -1). This is more correct, but will incur a performance hit when inert is enabled or disabled. The GoogleChrome hosted polyfill simply overloads focus and related events to prevent focus.

Release

Compile code with Closure Compiler.

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name inert-polyfill.min.js
// ==/ClosureCompiler==

// code here

More Repositories

1

lighthouse

Automated auditing, performance metrics, and best practices for the web.
JavaScript
27,804
star
2

chrome-extensions-samples

Chrome Extensions Samples
JavaScript
13,907
star
3

workbox

📦 Workbox: JavaScript libraries for Progressive Web Apps
JavaScript
12,091
star
4

web-vitals

Essential metrics for a healthy site.
JavaScript
7,111
star
5

lighthouse-ci

Automate running Lighthouse for every commit, viewing the changes, and preventing regressions
JavaScript
6,210
star
6

rendertron

A Headless Chrome rendering solution
TypeScript
5,926
star
7

samples

A repo containing samples tied to new functionality in each release of Google Chrome.
HTML
5,709
star
8

web.dev

The frontend, backend, and content source code for web.dev
Nunjucks
3,544
star
9

dialog-polyfill

Polyfill for the HTML dialog element
JavaScript
2,425
star
10

web-vitals-extension

A Chrome extension to measure essential metrics for a healthy site
CSS
2,318
star
11

accessibility-developer-tools

This is a library of accessibility-related testing and utility code.
JavaScript
2,274
star
12

developer.chrome.com

The frontend, backend, and content source code for developer.chrome.com
HTML
1,660
star
13

custom-tabs-client

Chrome custom tabs examples
Java
1,399
star
14

chrome-launcher

Launch Google Chrome with ease from node.
TypeScript
1,166
star
15

proxy-polyfill

Proxy object polyfill
JavaScript
1,127
star
16

omnitone

Spatial Audio Rendering on the web.
JavaScript
840
star
17

devtools-docs

The legacy documentation for Chrome DevTools.
HTML
686
star
18

android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Java
655
star
19

chromium-dashboard

Chrome Status Dashboard
Python
624
star
20

OriginTrials

Enabling safe experimentation with web APIs
Bikeshed
520
star
21

audion

Audion is a Chrome extension that adds a Web Audio panel to Developer Tools. This panel visualizes the web audio graph in real-time.
TypeScript
357
star
22

related-website-sets

Python
282
star
23

chrome-app-codelab

The goal of this tutorial is to get you building Chrome apps fast. Once you've completed the tutorial, you will have a simple Todo app. We've done our best to capture some of the trickier parts to the development process keeping the sample simple and straightforward.
JavaScript
214
star
24

lighthouse-stack-packs

Lighthouse Stack Packs
JavaScript
207
star
25

CrUX

The place to share queries, ideas, or issues related to the Chrome UX Report
Jupyter Notebook
201
star
26

chrome-types

Code to parse Chrome's internal extension type definitions—published on NPM as chrome-types
JavaScript
157
star
27

devtools-samples

Samples for demonstrating DevTools features.
HTML
149
star
28

ip-protection

147
star
29

CertificateTransparency

HTML
139
star
30

browser-bug-search

Search across all major browser vendor issue trackers
JavaScript
113
star
31

multi-device

Chrome multi-device (mobile) docs
HTML
102
star
32

kino

A sample offline streaming video PWA built for web.dev/media
JavaScript
92
star
33

jank-busters

Resources for jank busting on the web.
JavaScript
64
star
34

webstore-docs

Developer docs for Chrome Web Store:
HTML
64
star
35

budget.json

37
star
36

private-tokens

37
star
37

webdev-infra

JavaScript
36
star
38

.github

10
star
39

.allstar

7
star
40

CertificateTransparency-todelete

HTML
7
star
41

lighthouse-plugin-example

JavaScript
1
star