![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
focus-within-polyfill
Advanced tools
:focus-within
Pseudo-Class PolyfillThis package will add two event listeners, one on the focus event and one on the blur event to trigger the automatic apply and remove of a custom attribute to indicate wheter the Element should have a :focus-within
pseudo-class. In order to do so and be compatible with older version of IE and Edge the setAttribute
method is used to set both attributes and classes. This will prevent error like: classList
is undefined for SVG Element.
:focus-within
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.
This package is available both as production ready script and as a package. The script can be downloaded here, or installed with a package manager.
# npm
npm install focus-within-polyfill --save
# yarn
yarn add focus-within-polyfill
When including the polyfill in a script tag, call window.focusWithin.polyfill(string)
method to initialize the polyfill:
/* ES5 */
<script src='https://unpkg.com/focus-within-polyfill/dist/focus-within-polyfill.js'></script>
focusWithin.polyfill()
In addition this library is available as a es6 module that can be imported and bundled up with any build tool. If you are importing it as a dependency, make sure to call the polyfill method:
/* ES6 */
import focusWithin from 'focus-within-polyfill'
focusWithin.polyfill()
After import and initialization the polyfill will kick in only if :focus-within
is not supported in the current browser. By default the [focus-within]
attribute will be added automatically to every element that should have the pseudo-class. Additionally in the initialization fase a custom class or custom attribute can be specified like in the example below:
focusWithin.polyfill('[focus-within]'); // default
focusWithin.polyfill('[focus-inside]'); // custom attribute
focusWithin.polyfill('.focus-within'); // custom class
This polyfill does not support shadow DOM. The goal is to polyfill a feature that is missing in IE and EDGE and since shadow DOM is another feature that needs polyfilling in this browser I won't implement such feature, but any PR is well accepted.
FAQs
Small vanilla javascript that feature detect the :focus-within pseudo selector and polyfills it with a standard css class if necessary.
The npm package focus-within-polyfill receives a total of 3,442 weekly downloads. As such, focus-within-polyfill popularity was classified as popular.
We found that focus-within-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.