Skip to content

Commit 569c279

Browse files
committed
Fix issue where motion variants incorrectly stack with group-hover variants
1 parent fb2c85e commit 569c279

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

__tests__/responsiveAtRule.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,32 +111,37 @@ test('it can generate responsive variants when classes have non-standard charact
111111
@responsive {
112112
.hover\\:banana { color: yellow; }
113113
.chocolate-2\\.5 { color: brown; }
114+
.group:hover .group-hover\\:toast { color: black; }
114115
}
115116
116117
@tailwind screens;
117-
`
118+
`
118119

119120
const output = `
120121
@layer utilities {
121122
.hover\\:banana { color: yellow; }
122123
.chocolate-2\\.5 { color: brown; }
124+
.group:hover .group-hover\\:toast { color: black; }
123125
}
124126
@media (min-width: 500px) {
125127
@layer utilities {
126128
.sm\\:hover\\:banana { color: yellow; }
127129
.sm\\:chocolate-2\\.5 { color: brown; }
130+
.group:hover .sm\\:group-hover\\:toast { color: black; }
128131
}
129132
}
130133
@media (min-width: 750px) {
131134
@layer utilities {
132135
.md\\:hover\\:banana { color: yellow; }
133136
.md\\:chocolate-2\\.5 { color: brown; }
137+
.group:hover .md\\:group-hover\\:toast { color: black; }
134138
}
135139
}
136140
@media (min-width: 1000px) {
137141
@layer utilities {
138142
.lg\\:hover\\:banana { color: yellow; }
139143
.lg\\:chocolate-2\\.5 { color: brown; }
144+
.group:hover .lg\\:group-hover\\:toast { color: black; }
140145
}
141146
}
142147
`

__tests__/variantsAtRule.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ test('it can generate motion-safe and motion-reduce variants', () => {
252252

253253
test('motion-reduce variants stack with basic variants', () => {
254254
const input = `
255-
@variants motion-reduce, hover {
255+
@variants motion-reduce, hover, group-hover {
256256
.banana { color: yellow; }
257257
.chocolate { color: brown; }
258258
}
@@ -263,11 +263,15 @@ test('motion-reduce variants stack with basic variants', () => {
263263
.chocolate { color: brown; }
264264
.hover\\:banana:hover { color: yellow; }
265265
.hover\\:chocolate:hover { color: brown; }
266+
.group:hover .group-hover\\:banana { color: yellow; }
267+
.group:hover .group-hover\\:chocolate { color: brown; }
266268
@media (prefers-reduced-motion: reduce) {
267269
.motion-reduce\\:banana { color: yellow; }
268270
.motion-reduce\\:chocolate { color: brown; }
269271
.motion-reduce\\:hover\\:banana:hover { color: yellow; }
270272
.motion-reduce\\:hover\\:chocolate:hover { color: brown; }
273+
.group:hover .motion-reduce\\:group-hover\\:banana { color: yellow; }
274+
.group:hover .motion-reduce\\:group-hover\\:chocolate { color: brown; }
271275
}
272276
`
273277

@@ -279,7 +283,7 @@ test('motion-reduce variants stack with basic variants', () => {
279283

280284
test('motion-safe variants stack with basic variants', () => {
281285
const input = `
282-
@variants motion-safe, hover {
286+
@variants motion-safe, hover, group-hover {
283287
.banana { color: yellow; }
284288
.chocolate { color: brown; }
285289
}
@@ -290,11 +294,15 @@ test('motion-safe variants stack with basic variants', () => {
290294
.chocolate { color: brown; }
291295
.hover\\:banana:hover { color: yellow; }
292296
.hover\\:chocolate:hover { color: brown; }
297+
.group:hover .group-hover\\:banana { color: yellow; }
298+
.group:hover .group-hover\\:chocolate { color: brown; }
293299
@media (prefers-reduced-motion: no-preference) {
294300
.motion-safe\\:banana { color: yellow; }
295301
.motion-safe\\:chocolate { color: brown; }
296302
.motion-safe\\:hover\\:banana:hover { color: yellow; }
297303
.motion-safe\\:hover\\:chocolate:hover { color: brown; }
304+
.group:hover .motion-safe\\:group-hover\\:banana { color: yellow; }
305+
.group:hover .motion-safe\\:group-hover\\:chocolate { color: brown; }
298306
}
299307
`
300308

src/lib/substituteVariantsAtRules.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import postcss from 'postcss'
33
import selectorParser from 'postcss-selector-parser'
44
import generateVariantFunction from '../util/generateVariantFunction'
55
import prefixSelector from '../util/prefixSelector'
6+
import buildSelectorVariant from '../util/buildSelectorVariant'
67

78
function generatePseudoClassVariant(pseudoClass, selectorPrefix = pseudoClass) {
89
return generateVariantFunction(({ modifySelectors, separator }) => {
@@ -25,11 +26,9 @@ const defaultVariantGenerators = config => ({
2526
default: generateVariantFunction(() => {}),
2627
'motion-safe': generateVariantFunction(({ container, separator, modifySelectors }) => {
2728
const modified = modifySelectors(({ selector }) => {
28-
return selectorParser(selectors => {
29-
selectors.walkClasses(sel => {
30-
sel.value = `motion-safe${separator}${sel.value}`
31-
})
32-
}).processSync(selector)
29+
return buildSelectorVariant(selector, 'motion-safe', separator, message => {
30+
throw container.error(message)
31+
})
3332
})
3433
const mediaQuery = postcss.atRule({
3534
name: 'media',
@@ -40,11 +39,9 @@ const defaultVariantGenerators = config => ({
4039
}),
4140
'motion-reduce': generateVariantFunction(({ container, separator, modifySelectors }) => {
4241
const modified = modifySelectors(({ selector }) => {
43-
return selectorParser(selectors => {
44-
selectors.walkClasses(sel => {
45-
sel.value = `motion-reduce${separator}${sel.value}`
46-
})
47-
}).processSync(selector)
42+
return buildSelectorVariant(selector, 'motion-reduce', separator, message => {
43+
throw container.error(message)
44+
})
4845
})
4946
const mediaQuery = postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' })
5047
mediaQuery.append(modified)

0 commit comments

Comments
 (0)