Add focus-within variant

This commit is contained in:
Paulo 2018-05-04 14:47:28 +02:00
parent 14f1ba6cb9
commit 9e4e8a6d05
3 changed files with 24 additions and 1 deletions

View File

@ -69,6 +69,27 @@ test('it can generate focus variants', () => {
})
})
test('it can generate focus-within variants', () => {
const input = `
@variants focus-within {
.banana { color: yellow; }
.chocolate { color: brown; }
}
`
const output = `
.banana { color: yellow; }
.chocolate { color: brown; }
.focus-within\\:banana:focus-within { color: yellow; }
.focus-within\\:chocolate:focus-within { color: brown; }
`
return run(input).then(result => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
})
})
test('it can generate group-hover variants', () => {
const input = `
@variants group-hover {

View File

@ -828,6 +828,7 @@ module.exports = {
| - responsive
| - hover
| - focus
| - focus-within
| - active
| - group-hover
|

View File

@ -30,6 +30,7 @@ const variantGenerators = {
},
hover: generatePseudoClassVariant('hover'),
focus: generatePseudoClassVariant('focus'),
'focus-within': generatePseudoClassVariant('focus-within'),
active: generatePseudoClassVariant('active'),
}
@ -48,7 +49,7 @@ export default function(config) {
atRule.before(atRule.clone().nodes)
_.forEach(['group-hover', 'hover', 'focus', 'active'], variant => {
_.forEach(['group-hover', 'hover', 'focus', 'focus-within', 'active'], variant => {
if (variants.includes(variant)) {
variantGenerators[variant](atRule, unwrappedConfig)
}