postcss-focus

7.0.0last stable release 2 years ago
Complexity Score
Low
Open Issues
0
Dependent Projects
55
Weekly Downloadsglobal
12,800

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

PostCSS Focus

PostCSS plugin to add :focus-visible selector to every :hover for keyboard accessibility.

See also postcss-pseudo-class-enter for more explicit way.

*:focus-visible {
  outline: 0;
}
.button:hover {
  background: red;
}
*:focus-visible {
  outline: 0;
}
.button:hover {
    background: red;
}
.button:focus-visible {
  background: red;
}

If there is a :focus-visible selector, it will be excluded from the processing.

.a:hover, .b:hover {
  outline: 0;
}
.b:focus-visible {
  background: red;
}
.a:hover, .b:hover, .a:focus-visible {
  outline: 0;
}
.b:focus-visible {
  background: red;
}

Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-focus

Step 2: Check your project for existing PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-focus'),
    require('autoprefixer')
  ]
}

Options

module.exports = {
  plugins: [
    require('postcss-focus')({
      oldFocus: true,
      splitRules: false,
    })
  ]
}

oldFocus

Type: boolean. Default: false.

Enable if you need to add the old :focus instead of :focus-visible selector to every :hover.

splitRules

Type: boolean. Default: true.

Disable if you need to append the selector. If you don’t need to support browsers, which doesn’t support :focus-visible, you can safely disable this option.

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
4.20
Test Coverage
No Data
Follows Semver
Yes
Github Stars
117
Dependenciestotal
0
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute postcss-focus in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install postcss-focus
Processing...
Done

10 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.