Skip to content

Commit 81f52a2

Browse files
authored
Ensure complex variants with multiple classes work (#6311)
* ensure complex variants with multiple classes work * update changelog
1 parent 99baa6e commit 81f52a2

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Ensure complex variants with multiple classes work [#6311](https://github.com/tailwindlabs/tailwindcss/pull/6311)
1113

1214
## [3.0.0] - 2021-12-09
1315

src/lib/expandApplyAtRules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ function processApply(root, context) {
129129
// TODO: Should we use postcss-selector-parser for this instead?
130130
function replaceSelector(selector, utilitySelectors, candidate) {
131131
let needle = `.${escapeClassName(candidate)}`
132-
let utilitySelectorsList = utilitySelectors.split(/\s*,\s*/g)
132+
let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g)
133133

134134
return selector
135-
.split(/\s*,\s*/g)
135+
.split(/\s*\,(?![^(]*\))\s*/g)
136136
.map((s) => {
137137
let replaced = []
138138

tests/variants.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,44 @@ describe('custom advanced variants', () => {
167167
`)
168168
})
169169
})
170+
171+
test('using multiple classNames in your custom variant', () => {
172+
let config = {
173+
content: [
174+
{
175+
raw: html` <div class="my-variant:underline test"></div> `,
176+
},
177+
],
178+
plugins: [
179+
function ({ addVariant }) {
180+
addVariant('my-variant', '&:where(.one, .two, .three)')
181+
},
182+
],
183+
}
184+
185+
let input = css`
186+
@tailwind components;
187+
@tailwind utilities;
188+
189+
@layer components {
190+
.test {
191+
@apply my-variant:italic;
192+
}
193+
}
194+
`
195+
196+
return run(input, config).then((result) => {
197+
return expect(result.css).toMatchFormattedCss(css`
198+
.test:where(.one, .two, .three) {
199+
font-style: italic;
200+
}
201+
202+
.my-variant\:underline:where(.one, .two, .three) {
203+
text-decoration: underline;
204+
}
205+
`)
206+
})
207+
})
170208
})
171209

172210
test('stacked peer variants', async () => {

0 commit comments

Comments
 (0)