Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where dark variant in 'class' mode was incompatible with 'group-hover' variant #2337

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [1.8.3] - 2020-09-05

Expand Down
20 changes: 19 additions & 1 deletion __tests__/darkMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ test('dark mode variants stack with other variants', () => {

test('dark mode variants stack with other variants when using the class strategy', () => {
const input = `
@variants responsive, dark, hover, focus {
@variants responsive, dark, group-hover, hover, focus {
.text-red {
color: red;
}
Expand All @@ -200,6 +200,9 @@ test('dark mode variants stack with other variants when using the class strategy
.text-red {
color: red;
}
.group:hover .group-hover\\:text-red {
color: red;
}
.hover\\:text-red:hover {
color: red;
}
Expand All @@ -209,6 +212,9 @@ test('dark mode variants stack with other variants when using the class strategy
.dark .dark\\:text-red {
color: red;
}
.dark .group:hover .dark\\:group-hover\\:text-red {
color: red;
}
.dark .dark\\:hover\\:text-red:hover {
color: red;
}
Expand All @@ -219,6 +225,9 @@ test('dark mode variants stack with other variants when using the class strategy
.sm\\:text-red {
color: red;
}
.group:hover .sm\\:group-hover\\:text-red {
color: red;
}
.sm\\:hover\\:text-red:hover {
color: red;
}
Expand All @@ -228,6 +237,9 @@ test('dark mode variants stack with other variants when using the class strategy
.dark .sm\\:dark\\:text-red {
color: red;
}
.dark .group:hover .sm\\:dark\\:group-hover\\:text-red {
color: red;
}
.dark .sm\\:dark\\:hover\\:text-red:hover {
color: red;
}
Expand All @@ -239,6 +251,9 @@ test('dark mode variants stack with other variants when using the class strategy
.lg\\:text-red {
color: red;
}
.group:hover .lg\\:group-hover\\:text-red {
color: red;
}
.lg\\:hover\\:text-red:hover {
color: red;
}
Expand All @@ -248,6 +263,9 @@ test('dark mode variants stack with other variants when using the class strategy
.dark .lg\\:dark\\:text-red {
color: red;
}
.dark .group:hover .lg\\:dark\\:group-hover\\:text-red {
color: red;
}
.dark .lg\\:dark\\:hover\\:text-red:hover {
color: red;
}
Expand Down
17 changes: 11 additions & 6 deletions src/flagged/darkModeVariant.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import selectorParser from 'postcss-selector-parser'
import buildSelectorVariant from '../util/buildSelectorVariant'
import defaultConfig from '../../defaultConfig'

Expand Down Expand Up @@ -31,13 +30,19 @@ export default {
}

if (config('dark') === 'class') {
const parser = selectorParser(selectors => {
selectors.walkClasses(sel => {
sel.value = `dark${separator}${sel.value}`
sel.parent.insertBefore(sel, selectorParser().astSync(prefix('.dark ')))
const modified = modifySelectors(({ selector }) => {
return buildSelectorVariant(selector, 'dark', separator, message => {
throw container.error(message)
})
})
return modifySelectors(({ selector }) => parser.processSync(selector))

modified.walkRules(rule => {
rule.selectors = rule.selectors.map(selector => {
return `${prefix('.dark ')} ${selector}`
})
})

return modified
}

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