Skip to content

Small vanilla javascript that feature detect the :focus-within pseudo selector and polyfills it with a standard css class if necessary.

License

Notifications You must be signed in to change notification settings

mcalmus/focus-within-polyfill

Repository files navigation

:focus-within Pseudo-Class Polyfill

Build Status

The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus.

More information on MDN.

How to use

This package is available both as production ready script and as a package. The script can be downloaded here, or install the package as follow.

# npm
npm install focus-within-polyfill --save

# yarn
yarn add focus-within-polyfill

When the polyfill is included via a script tag it will run immediately after load. On the other hand when imported as a dependency, a call to polyfill method is required.

import focuswithin from "focus-within-polyfill";

// kick off!
focuswithin.polyfill();

Browser Support

  • Natively supported in Chrome
  • Natively supported in Firefox
  • Natively supported in Safari
  • Natively supported in Opera
  • IE 11
  • Edge

TODO

  • Write some tests and examples
  • Publish on npm

About

Small vanilla javascript that feature detect the :focus-within pseudo selector and polyfills it with a standard css class if necessary.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%