Gathering detailed insights and metrics for postcss-focus-within
Gathering detailed insights and metrics for postcss-focus-within
npm install postcss-focus-within
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.6
Supply Chain
99.2
Quality
81
Maintenance
100
Vulnerability
100
License
CSS (43.37%)
JavaScript (30.22%)
TypeScript (22.76%)
HTML (3.06%)
Nunjucks (0.48%)
Shell (0.1%)
Total Downloads
1,400,446,463
Last Day
1,007,528
Last Week
4,654,187
Last Month
21,360,955
Last Year
286,187,286
931 Stars
4,164 Commits
73 Forks
11 Watching
3 Branches
131 Contributors
Minified
Minified + Gzipped
Latest Version
9.0.1
Package Id
postcss-focus-within@9.0.1
Unpacked Size
31.78 kB
Size
7.66 kB
File Count
13
NPM Version
10.7.0
Node Version
22.1.0
Publised On
23 Oct 2024
Cumulative downloads
Total Downloads
Last day
-6.7%
1,007,528
Compared to previous day
Last week
-18.5%
4,654,187
Compared to previous week
Last month
5.7%
21,360,955
Compared to previous month
Last year
-13.5%
286,187,286
Compared to previous year
1
1
npm install postcss-focus-within --save-dev
PostCSS Focus Within lets you use the :focus-within
pseudo-class in CSS,
following the Selectors Level 4 specification.
To use this feature you need to do two things :
1.my-form-field:focus-within label { 2 background-color: yellow; 3} 4 5/* becomes */ 6 7.my-form-field[focus-within].js-focus-within label, .js-focus-within .my-form-field[focus-within] label { 8 background-color: yellow; 9} 10.my-form-field:focus-within label { 11 background-color: yellow; 12}
PostCSS Focus Within duplicates rules using the :focus-within
pseudo-class
with a [focus-within]
attribute selector, the same selector used by the
focus-within polyfill. This replacement selector can be changed using the
replaceWith
option. Also, the preservation of the original :focus-within
rule can be disabled using the preserve
option.
Add PostCSS Focus Within to your project:
1npm install postcss postcss-focus-within --save-dev
Use it as a PostCSS plugin:
1const postcss = require('postcss'); 2const postcssFocusWithin = require('postcss-focus-within'); 3 4postcss([ 5 postcssFocusWithin(/* pluginOptions */) 6]).process(YOUR_CSS /*, processOptions */);
The preserve
option determines whether the original notation
is preserved. By default, it is preserved.
1postcssFocusWithin({ preserve: false })
1.my-form-field:focus-within label { 2 background-color: yellow; 3} 4 5/* becomes */ 6 7.my-form-field[focus-within].js-focus-within label, .js-focus-within .my-form-field[focus-within] label { 8 background-color: yellow; 9}
The replaceWith
option defines the selector to replace :focus-within
. By
default, the replacement selector is [focus-within]
.
Please note that using a class, leverages classList
under the hood which
might not be supported on some old browsers such as IE9, so you may need
to polyfill classList
in those cases.
1postcssFocusWithin({ replaceWith: '.focus-within' });
1.my-form-field:focus-within label { 2 background-color: yellow; 3} 4 5/* becomes */ 6 7.my-form-field.focus-within.js-focus-within label, .js-focus-within .my-form-field.focus-within label { 8 background-color: yellow; 9} 10.my-form-field:focus-within label { 11 background-color: yellow; 12}
Note that changing this option implies that it needs to be passed to the browser polyfill as well.
The disablePolyfillReadyClass
option determines if selectors are prefixed with an indicator class.
This class is only set on your document if the polyfill loads and is needed.
By default this option is false
.
Set this to true
to prevent the class from being added.
1postcssFocusWithin({ disablePolyfillReadyClass: true })
1.my-form-field:focus-within label { 2 background-color: yellow; 3} 4 5/* becomes */ 6 7.my-form-field[focus-within] label { 8 background-color: yellow; 9} 10.my-form-field:focus-within label { 11 background-color: yellow; 12}
1import focusWithinInit from 'postcss-focus-within/browser'; 2 3focusWithinInit();
or
1<!-- When using a CDN url you will have to manually update the version number --> 2<script src="https://unpkg.com/postcss-focus-within@9.0.1/dist/browser-global.js"></script> 3<script>focusWithinInit()</script>
PostCSS Focus Within works in all major browsers, including Safari 6+ and Internet Explorer 9+ without any additional polyfills.
The force
option determines whether the library runs even if the browser
supports the selector or not. By default, it won't run if the browser does
support the selector.
1focusWithinInit({ force: true });
Similar to the option for the PostCSS Plugin, replaceWith
determines the
attribute or class to apply to an element when it's considered to be :focus-within
.
1focusWithinInit({ replaceWith: '.focus-within });
This option should be used if it was changed at PostCSS configuration level.
Given that Next.js imports packages both on the browser and on the server, you need to make sure that the package is only imported on the browser.
As outlined in the Next.js documentation, you need to load the package with a dynamic import:
1useEffect(async () => { 2 const focusWithinInit = (await import('postcss-focus-within/browser')).default; 3 focusWithinInit(); 4}, []);
No vulnerabilities found.
Reason
30 commit(s) and 11 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/23 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More