Socket
Socket
Sign inDemoInstall

postcss-focus-within

Package Overview
Dependencies
7
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-focus-within

Use the :focus-within pseudo-selector in CSS


Version published
Weekly downloads
5.2M
decreased by-10.47%
Maintainers
2
Install size
220 kB
Created
Weekly downloads
 

Readme

Source

PostCSS Focus Within PostCSS Logo

npm version CSS Standard Status Build Status Discord

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

It is the companion to the focus-within polyfill.

'Can I use' table

.my-form-field:focus-within label {
  background-color: yellow;
}

/* becomes */

.my-form-field[focus-within] label {
  background-color: yellow;
}

.my-form-field:focus-within label {
  background-color: yellow;
}

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.

Usage

Add PostCSS Focus Within to your project:

npm install postcss postcss-focus-within --save-dev

Use PostCSS Focus Within to process your CSS:

const postcssFocusWithin = require('postcss-focus-within');

postcssFocusWithin.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssFocusWithin = require('postcss-focus-within');

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

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

NodePostCSS CLIWebpackCreate React AppGulpGrunt

Options

preserve

The preserve option defines whether the original selector should remain. By default, the original selector is preserved.

focusWithin({ preserve: false });
.my-form-field:focus-within label {
  background-color: yellow;
}

/* becomes */

.my-form-field[focus-within] label {
  background-color: yellow;
}

replaceWith

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

focusWithin({ replaceWith: '.focus-within' });
.my-form-field:focus-within label {
  background-color: yellow;
}

/* becomes */

.my-form-field.focus-within label {
  background-color: yellow;
}

.my-form-field:focus-within label {
  background-color: yellow;
}

Keywords

FAQs

Last updated on 05 Feb 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc