Skip to content

Commit 0cf76cd

Browse files
authored
Fix issue where dark variant in 'class' mode was incompatible with 'group-hover' variant (#2337)
* Fix issue where dark variant in 'class' mode was incompatible with 'group-hover' variant * Update changelog
1 parent 0b48b4c commit 0cf76cd

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Fix [issue](https://github.com/tailwindlabs/tailwindcss/issues/2258) where inserting extra PurgeCSS control comments could break integrated PurgeCSS support
1111
- Rename `font-hairline` and `font-thin` to `font-thin` and `font-extralight` behind `standardFontWeights` flag ([#2333](https://github.com/tailwindlabs/tailwindcss/pull/2333))
12+
- Fix issue where dark variant in 'class' mode was incompatible with 'group-hover' variant ([#2337](https://github.com/tailwindlabs/tailwindcss/pull/2337))
1213

1314
## [1.8.3] - 2020-09-05
1415

__tests__/darkMode.test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test('dark mode variants stack with other variants', () => {
189189

190190
test('dark mode variants stack with other variants when using the class strategy', () => {
191191
const input = `
192-
@variants responsive, dark, hover, focus {
192+
@variants responsive, dark, group-hover, hover, focus {
193193
.text-red {
194194
color: red;
195195
}
@@ -200,6 +200,9 @@ test('dark mode variants stack with other variants when using the class strategy
200200
.text-red {
201201
color: red;
202202
}
203+
.group:hover .group-hover\\:text-red {
204+
color: red;
205+
}
203206
.hover\\:text-red:hover {
204207
color: red;
205208
}
@@ -209,6 +212,9 @@ test('dark mode variants stack with other variants when using the class strategy
209212
.dark .dark\\:text-red {
210213
color: red;
211214
}
215+
.dark .group:hover .dark\\:group-hover\\:text-red {
216+
color: red;
217+
}
212218
.dark .dark\\:hover\\:text-red:hover {
213219
color: red;
214220
}
@@ -219,6 +225,9 @@ test('dark mode variants stack with other variants when using the class strategy
219225
.sm\\:text-red {
220226
color: red;
221227
}
228+
.group:hover .sm\\:group-hover\\:text-red {
229+
color: red;
230+
}
222231
.sm\\:hover\\:text-red:hover {
223232
color: red;
224233
}
@@ -228,6 +237,9 @@ test('dark mode variants stack with other variants when using the class strategy
228237
.dark .sm\\:dark\\:text-red {
229238
color: red;
230239
}
240+
.dark .group:hover .sm\\:dark\\:group-hover\\:text-red {
241+
color: red;
242+
}
231243
.dark .sm\\:dark\\:hover\\:text-red:hover {
232244
color: red;
233245
}
@@ -239,6 +251,9 @@ test('dark mode variants stack with other variants when using the class strategy
239251
.lg\\:text-red {
240252
color: red;
241253
}
254+
.group:hover .lg\\:group-hover\\:text-red {
255+
color: red;
256+
}
242257
.lg\\:hover\\:text-red:hover {
243258
color: red;
244259
}
@@ -248,6 +263,9 @@ test('dark mode variants stack with other variants when using the class strategy
248263
.dark .lg\\:dark\\:text-red {
249264
color: red;
250265
}
266+
.dark .group:hover .lg\\:dark\\:group-hover\\:text-red {
267+
color: red;
268+
}
251269
.dark .lg\\:dark\\:hover\\:text-red:hover {
252270
color: red;
253271
}

src/flagged/darkModeVariant.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import selectorParser from 'postcss-selector-parser'
21
import buildSelectorVariant from '../util/buildSelectorVariant'
32
import defaultConfig from '../../defaultConfig'
43

@@ -31,13 +30,19 @@ export default {
3130
}
3231

3332
if (config('dark') === 'class') {
34-
const parser = selectorParser(selectors => {
35-
selectors.walkClasses(sel => {
36-
sel.value = `dark${separator}${sel.value}`
37-
sel.parent.insertBefore(sel, selectorParser().astSync(prefix('.dark ')))
33+
const modified = modifySelectors(({ selector }) => {
34+
return buildSelectorVariant(selector, 'dark', separator, message => {
35+
throw container.error(message)
3836
})
3937
})
40-
return modifySelectors(({ selector }) => parser.processSync(selector))
38+
39+
modified.walkRules(rule => {
40+
rule.selectors = rule.selectors.map(selector => {
41+
return `${prefix('.dark ')} ${selector}`
42+
})
43+
})
44+
45+
return modified
4146
}
4247

4348
throw new Error("The `dark` config option must be either 'media' or 'class'.")

0 commit comments

Comments
 (0)