Skip to content

Commit ed550b3

Browse files
authored
[0.3] Add parent-hover variant (tailwindlabs#251)
* Add parent-hover variant * Don't enable parent-hover on textColors module by default * Add tests, move parent-hover declarations to separate rules * Prettier-ignore long selector string
1 parent c165f1d commit ed550b3

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ test('it can generate focus variants', () => {
5050
})
5151
})
5252

53+
test('it can generate parent-hover variants', () => {
54+
const input = `
55+
@variants parent-hover {
56+
.banana { color: yellow; }
57+
.chocolate { color: brown; }
58+
}
59+
`
60+
61+
const output = `
62+
.banana { color: yellow; }
63+
.chocolate { color: brown; }
64+
.parent:hover .parent-hover${separator}banana { color: yellow; }
65+
.parent:hover .parent-hover${separator}chocolate { color: brown; }
66+
`
67+
68+
return run(input).then(result => {
69+
expect(result.css).toMatchCss(output)
70+
expect(result.warnings().length).toBe(0)
71+
})
72+
})
73+
5374
test('it can generate hover and focus variants', () => {
5475
const input = `
5576
@variants hover, focus {

src/lib/substituteVariantsAtRules.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const variantGenerators = {
1818
rule.selector = `.focus${config.options.separator}${rule.selector.slice(1)}:focus`
1919
})
2020

21+
container.before(cloned.nodes)
22+
},
23+
'parent-hover': (container, config) => {
24+
const cloned = container.clone()
25+
26+
cloned.walkRules(rule => {
27+
// prettier-ignore
28+
rule.selector = `.parent:hover .parent-hover${config.options.separator}${rule.selector.slice(1)}`
29+
})
30+
2131
container.before(cloned.nodes)
2232
},
2333
}
@@ -37,7 +47,7 @@ export default function(config) {
3747

3848
atRule.before(atRule.clone().nodes)
3949

40-
_.forEach(['focus', 'hover'], variant => {
50+
_.forEach(['focus', 'hover', 'parent-hover'], variant => {
4151
if (variants.includes(variant)) {
4252
variantGenerators[variant](atRule, unwrappedConfig)
4353
}

0 commit comments

Comments
 (0)