Skip to content

Commit f120967

Browse files
authored
Merge pull request #1824 from austin94/austin94/add-focus-visible-variant
Add :focus-visible variant
2 parents 74ed4c2 + 4187e6d commit f120967

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ test('it can generate focus-within variants', () => {
135135
})
136136
})
137137

138+
test('it can generate focus-visible variants', () => {
139+
const input = `
140+
@variants focus-visible {
141+
.banana { color: yellow; }
142+
.chocolate { color: brown; }
143+
}
144+
`
145+
146+
const output = `
147+
.banana { color: yellow; }
148+
.chocolate { color: brown; }
149+
.focus-visible\\:banana:focus-visible { color: yellow; }
150+
.focus-visible\\:chocolate:focus-visible { color: brown; }
151+
`
152+
153+
return run(input).then(result => {
154+
expect(result.css).toMatchCss(output)
155+
expect(result.warnings().length).toBe(0)
156+
})
157+
})
158+
138159
test('it can generate first-child variants', () => {
139160
const input = `
140161
@variants first {
@@ -415,7 +436,7 @@ test('variants are generated in the order specified', () => {
415436

416437
test('the built-in variant pseudo-selectors are appended before any pseudo-elements', () => {
417438
const input = `
418-
@variants hover, focus-within, focus, active, group-hover {
439+
@variants hover, focus-within, focus-visible, focus, active, group-hover {
419440
.placeholder-yellow::placeholder { color: yellow; }
420441
}
421442
`
@@ -424,6 +445,7 @@ test('the built-in variant pseudo-selectors are appended before any pseudo-eleme
424445
.placeholder-yellow::placeholder { color: yellow; }
425446
.hover\\:placeholder-yellow:hover::placeholder { color: yellow; }
426447
.focus-within\\:placeholder-yellow:focus-within::placeholder { color: yellow; }
448+
.focus-visible\\:placeholder-yellow:focus-visible::placeholder { color: yellow; }
427449
.focus\\:placeholder-yellow:focus::placeholder { color: yellow; }
428450
.active\\:placeholder-yellow:active::placeholder { color: yellow; }
429451
.group:hover .group-hover\\:placeholder-yellow::placeholder { color: yellow; }
@@ -624,7 +646,10 @@ test('plugin variants can wrap rules in another at-rule using the raw PostCSS AP
624646
...config.plugins,
625647
function({ addVariant, e }) {
626648
addVariant('supports-grid', ({ container, separator }) => {
627-
const supportsRule = postcss.atRule({ name: 'supports', params: '(display: grid)' })
649+
const supportsRule = postcss.atRule({
650+
name: 'supports',
651+
params: '(display: grid)',
652+
})
628653
supportsRule.nodes = container.nodes
629654
container.nodes = [supportsRule]
630655
supportsRule.walkRules(rule => {

src/lib/substituteVariantsAtRules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const defaultVariantGenerators = config => ({
5151
}),
5252
hover: generatePseudoClassVariant('hover'),
5353
'focus-within': generatePseudoClassVariant('focus-within'),
54+
'focus-visible': generatePseudoClassVariant('focus-visible'),
5455
focus: generatePseudoClassVariant('focus'),
5556
active: generatePseudoClassVariant('active'),
5657
visited: generatePseudoClassVariant('visited'),

0 commit comments

Comments
 (0)