JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5473251
  • Score
    100M100P100Q241085F
  • License CC0-1.0

Package Exports

  • postcss-focus-within

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss-focus-within) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostCSS Focus Within PostCSS Logo

NPM Version Build Status Windows Build Status Gitter Chat

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

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

/* becomes */

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

PostCSS Focus Within replaces the :focus-within pseudo-selector with a .focus-within class selector, the same selector used by the focus-within polyfill. The replacement selector can be changed using the replaceWith option.

Usage

Add PostCSS Focus Within to your build tool:

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

Node

Use PostCSS Focus Within to process your CSS:

import focusWithin from 'postcss-focus-within';

focusWithin.process(YOUR_CSS);

PostCSS

Add PostCSS to your build tool:

npm install postcss --save-dev

Use PostCSS Focus Within as a plugin:

import postcss from 'gulp-postcss';
import focusWithin from 'postcss-focus-within';

postcss([
  focusWithin()
]).process(YOUR_CSS);

Webpack

Add PostCSS Loader to your build tool:

npm install postcss-loader --save-dev

Use PostCSS Focus Within in your Gulpfile:

import focusWithin from 'postcss-focus-within';

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          { loader: 'postcss-loader', options: {
            ident: 'postcss',
            plugins: () => [ focusWithin() ]
          } }
        ]
      }
    ]
  }
}

Gulp

Add Gulp PostCSS to your build tool:

npm install gulp-postcss --save-dev

Use PostCSS Focus Within in your Gulpfile:

import postcss from 'gulp-postcss';
import focusWithin from 'postcss-focus-within';

gulp.task('css', () => gulp.src('./src/*.css').pipe(
  postcss([
    focusWithin()
  ])
).pipe(
  gulp.dest('.')
));

Grunt

Add Grunt PostCSS to your build tool:

npm install grunt-postcss --save-dev

Use PostCSS Focus Within in your Gruntfile:

import focusWithin from 'postcss-focus-within';

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
  postcss: {
    options: {
      use: [
       focusWithin()
      ]
    },
    dist: {
      src: '*.css'
    }
  }
});

Options

replaceWith

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

focusWithin({ replaceWith: '.focus-within' });
:focus:not(:focus-within) {
  outline: none;
}

/* becomes */

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