Skip to content

Commit eeb2947

Browse files
committed
Properly handle pseudo-elements with group-hover variant
1 parent 737f1ec commit eeb2947

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ test('variants are generated in the order specified', () => {
220220

221221
test('the built-in variant pseudo-selectors are appended before any pseudo-elements', () => {
222222
const input = `
223-
@variants hover, focus-within, focus, active {
223+
@variants hover, focus-within, focus, active, group-hover {
224224
.placeholder-yellow::placeholder { color: yellow; }
225225
}
226226
`
@@ -231,6 +231,7 @@ test('the built-in variant pseudo-selectors are appended before any pseudo-eleme
231231
.focus-within\\:placeholder-yellow:focus-within::placeholder { color: yellow; }
232232
.focus\\:placeholder-yellow:focus::placeholder { color: yellow; }
233233
.active\\:placeholder-yellow:active::placeholder { color: yellow; }
234+
.group:hover .group-hover\\:placeholder-yellow::placeholder { color: yellow; }
234235
`
235236

236237
return run(input).then(result => {

src/lib/substituteVariantsAtRules.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ function ensureIncludesDefault(variants) {
2424
const defaultVariantGenerators = {
2525
default: generateVariantFunction(() => {}),
2626
'group-hover': generateVariantFunction(({ modifySelectors, separator }) => {
27-
return modifySelectors(({ className }) => {
28-
return `.group:hover .${e(`group-hover${separator}${className}`)}`
27+
return modifySelectors(({ selector }) => {
28+
return selectorParser(selectors => {
29+
selectors.walkClasses(sel => {
30+
sel.value = `group-hover${separator}${sel.value}`
31+
sel.parent.insertBefore(sel, selectorParser().astSync('.group:hover '))
32+
})
33+
}).processSync(selector)
2934
})
3035
}),
3136
hover: generatePseudoClassVariant('hover'),

0 commit comments

Comments
 (0)