Skip to content

Commit c684cb0

Browse files
Yvain Liechtiromainmenke
Yvain Liechti
authored andcommitted
rename :focus-ring and .focus-ring as :focus-visible and .focus-visible
1 parent 6f07a63 commit c684cb0

File tree

7 files changed

+1487
-54
lines changed

7 files changed

+1487
-54
lines changed

plugins/postcss-focus-visible/.tape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
assignTo: cache
1212
},
1313
after: () => {
14-
const expectJSON = '[".focus-ring",".focus-ring test","test .focus-ring","test test.focus-ring","test .focus-ring test","test test.focus-ring test","test .focus-ring .focus-ring test","test :matches(.focus-ring) test","test :matches(.focus-ring test) test","test :matches(test .focus-ring) test","test :matches(test test.focus-ring) test","test :matches(test .focus-ring test) test","test :matches(test test.focus-ring test) test","test :matches(test .focus-ring .focus-ring test) test"]';
14+
const expectJSON = '[".focus-visible",".focus-visible test","test .focus-visible","test test.focus-visible","test .focus-visible test","test test.focus-visible test","test .focus-visible .focus-visible test","test :matches(.focus-visible) test","test :matches(.focus-visible test) test","test :matches(test .focus-visible) test","test :matches(test test.focus-visible) test","test :matches(test .focus-visible test) test","test :matches(test test.focus-visible test) test","test :matches(test .focus-visible .focus-visible test) test"]';
1515
const resultJSON = JSON.stringify(cache);
1616

1717
if (expectJSON !== resultJSON) {

plugins/postcss-focus-visible/README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
[![Windows Build Status][win-img]][win-url]
66
[![Gitter Chat][git-img]][git-url]
77

8-
[PostCSS Focus Ring] lets you use the `:focus-ring` pseudo-selector in CSS,
8+
[PostCSS Focus Ring] lets you use the `:focus-visible` pseudo-selector in CSS,
99
following the [Selectors Level 4] specification.
1010

1111
```css
12-
:focus:not(:focus-ring) {
12+
:focus:not(:focus-visible) {
1313
outline: none;
1414
}
1515
```
1616

17-
Use PostCSS Focus Ring alongside the [focus-ring polyfill] to swap the
17+
Use PostCSS Focus Ring alongside the [focus-visible polyfill] to swap the
1818
pseudo-selector for a class, which maintains the same selector weight.
1919

2020
```css
21-
:focus:not(.focus-ring) {
21+
:focus:not(.focus-visible) {
2222
outline: none;
2323
}
2424
```
@@ -35,9 +35,9 @@ require('postcss-focus-ring')({
3535

3636
```json
3737
[
38-
".focus-ring",
39-
".x-component-outside .focus-ring",
40-
".focus-ring .x-component-inside",
38+
".focus-visible",
39+
".x-component-outside .focus-visible",
40+
".focus-visible .x-component-inside",
4141
]
4242
```
4343

@@ -51,14 +51,14 @@ require('postcss-focus-ring')({
5151

5252
```js
5353
export default [
54-
".focus-ring",
55-
".x-component-outside .focus-ring",
56-
".focus-ring .x-component-inside",
54+
".focus-visible",
55+
".x-component-outside .focus-visible",
56+
".focus-visible .x-component-inside",
5757
];
5858
```
5959

6060
With these variables synchronized to JavaScript, they can be used alongside the
61-
[focus-ring polyfill].
61+
[focus-visible polyfill].
6262

6363
## Usage
6464

@@ -154,15 +154,15 @@ require('postcss-focus-ring')({ /* options */ });
154154
#### exportAs
155155

156156
`exportAs` is used to export transformed selectors originally containing the
157-
`:focus-ring` pseudo-selector.
157+
`:focus-visible` pseudo-selector.
158158

159159
- If a `js` string is passed, the selectors will be exported as JavaScript.
160160
- If a `json` string is passed, the selectors will be exported as JSON.
161161

162162
#### exportTo
163163

164164
`exportTo` is the path to where your JSON or JavaScript will be saved. By
165-
default, it is the CSS source file with an additional `focus-ring-selectors`
165+
default, it is the CSS source file with an additional `focus-visible-selectors`
166166
and `.js` or `.json` extension.
167167

168168
#### assignTo
@@ -183,5 +183,5 @@ be useful if running the plugin on the client side.
183183
[PostCSS]: https://github.com/postcss/postcss
184184
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
185185
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
186-
[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#the-focusring-pseudo
187-
[focus-ring polyfill]: https://github.com/WICG/focus-ring
186+
[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo
187+
[focus-visible polyfill]: https://github.com/WICG/focus-ring

plugins/postcss-focus-visible/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ const postcss = require('postcss');
44
const parser = require('postcss-selector-parser');
55

66
// plugin
7-
module.exports = postcss.plugin('postcss-focus-ring', (opts) => (root) => { // eslint-disable-line consistent-return
7+
module.exports = postcss.plugin('postcss-focus-visible', (opts) => (root) => { // eslint-disable-line consistent-return
88
// transformed cache
99
const transformed = [];
1010

1111
// walk each matching rule
12-
root.walkRules(/:focus-ring\b/, (rule) => {
12+
root.walkRules(/:focus-visible\b/, (rule) => {
1313
// original selector
1414
const originalSelector = rule.selector;
1515

1616
// transformed selector
1717
const transformedSelector = parser((selectors) => {
1818
// for each selector part
1919
selectors.walk((selector) => {
20-
// if the selector part is a :focus-ring pseudo
21-
if (selector.type === 'pseudo' && selector.value === ':focus-ring') {
22-
// change it to a .focus-ring class
23-
selector.value = '.focus-ring';
20+
// if the selector part is a :focus-visible pseudo
21+
if (selector.type === 'pseudo' && selector.value === ':focus-visible') {
22+
// change it to a .focus-visible class
23+
selector.value = '.focus-visible';
2424
selector.type = 'class';
2525
}
2626
});
@@ -50,7 +50,7 @@ module.exports = postcss.plugin('postcss-focus-ring', (opts) => (root) => { // e
5050
// destination path
5151
const destination = `${ opts.destination || `${
5252
root.source && root.source.input && root.source.input.file && root.source.input.file || 'css'
53-
}.focus-ring-selectors.${ opts.exportAs === 'js' ? 'js' : 'json' }` }`;
53+
}.focus-visible-selectors.${ opts.exportAs === 'js' ? 'js' : 'json' }` }`;
5454

5555
// stringified contents
5656
const json = JSON.stringify(transformedClean, null, ' ');

0 commit comments

Comments
 (0)