postcss-focus-visible
Use the :focus-visible pseudo-selector in CSS
Last updated 3 years ago by alaguna .
CC0-1.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install postcss-focus-visible 
SYNC missed versions from official npm registry.

PostCSS Focus Visible PostCSS Logo

npm version CSS Standard Status Build Status Discord

npm install postcss-focus-visible --save-dev

PostCSS Focus Visible lets you use the :focus-visible pseudo-class in CSS, following the Selectors Level 4 specification.

To use this feature you need to do two things :

'Can I use' table


```pcss
:focus:not(:focus-visible) {
	outline: none;
}

/* becomes */

:focus:not(.focus-visible).js-focus-visible, .js-focus-visible :focus:not(.focus-visible) {
	outline: none;
}
:focus:not(:focus-visible) {
	outline: none;
}

PostCSS Focus Visible duplicates rules using the :focus-visible pseudo-class with a .focus-visible class selector, the same selector used by the focus-visible polyfill.

Usage

Add PostCSS Focus Visible to your project:

npm install postcss postcss-focus-visible --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssFocusVisible = require('postcss-focus-visible');

postcss([
	postcssFocusVisible(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Focus Visible runs in all Node environments, with special instructions for:

Options

preserve

The preserve option determines whether the original notation is preserved. By default, it is preserved.

postcssFocusVisible({ preserve: false })
:focus:not(:focus-visible) {
	outline: none;
}

/* becomes */

:focus:not(.focus-visible).js-focus-visible, .js-focus-visible :focus:not(.focus-visible) {
	outline: none;
}

replaceWith

The replaceWith option defines the selector to replace :focus-visible. By default, the replacement selector is .focus-visible.

postcssFocusVisible({ replaceWith: '[data-focus-visible-added]' })
:focus:not(:focus-visible) {
	outline: none;
}

/* becomes */

<example.preserve-true.expect.css>

Note that if you want to keep using focus-visible polyfill, the only acceptable value would be [data-focus-visible-added], given that the polyfill does not support arbitrary values.

disablePolyfillReadyClass

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.

postcssFocusVisible({ disablePolyfillReadyClass: true })
:focus:not(:focus-visible) {
	outline: none;
}

/* becomes */

:focus:not(.focus-visible) {
	outline: none;
}
:focus:not(:focus-visible) {
	outline: none;
}

Current Tags

  • 10.0.1                                ...           latest (22 days ago)

18 Versions

  • 10.0.1                                ...           22 days ago
  • 10.0.0                                ...           3 months ago
  • 9.0.1                                ...           a year ago
  • 9.0.0                                ...           a year ago
  • 8.0.2                                ...           2 years ago
  • 8.0.1                                ...           2 years ago
  • 8.0.0                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 6.0.4                                ...           3 years ago
  • 6.0.3                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.0.0                                ...           5 years ago
  • 4.0.0                                ...           6 years ago
  • 3.0.0                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE