Skip to content

Commit 50024e4

Browse files
committed
Fix grouping using different variant types inside nested groups
1 parent b0e1f47 commit 50024e4

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/lib/generateRules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function* resolveMatches(candidate, context, original = candidate) {
458458
if (flagEnabled(context.tailwindConfig, 'variantGrouping')) {
459459
if (classCandidate.startsWith('(') && classCandidate.endsWith(')')) {
460460
let base = variants.slice().reverse().join(separator)
461-
for (let part of classCandidate.slice(1, -1).split(/\,(?![^(]*\))/g)) {
461+
for (let part of splitAtTopLevelOnly(classCandidate.slice(1, -1), ',')) {
462462
yield* resolveMatches(base + separator + part, context, original)
463463
}
464464
}

tests/variant-grouping.test.js

+51
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,57 @@ it('should be possible to use nested multiple grouped variants', () => {
178178
})
179179
})
180180

181+
it('should be possible to mix and match nesting and different variant combinations', () => {
182+
let config = {
183+
experimental: 'all',
184+
content: [
185+
{
186+
raw: html`<div
187+
class="md:[&>*]:(text-black,dark:(text-white,hover:[@supports(color:green)]:[&:nth-child(2n=1)]:text-gray-100))"
188+
></div>`,
189+
},
190+
],
191+
corePlugins: { preflight: false },
192+
plugins: [],
193+
}
194+
195+
let input = css`
196+
@tailwind utilities;
197+
`
198+
199+
return run(input, config).then((result) => {
200+
expect(result.css).toMatchFormattedCss(css`
201+
@media (min-width: 768px) {
202+
.md\:\[\&\>\*\]\:\(text-black\2c
203+
dark\:\(text-white\2c
204+
hover\:\[\@supports\(color\:green\)\]\:\[\&\:nth-child\(2n\=1\)\]\:text-gray-100\)\)
205+
> * {
206+
--tw-text-opacity: 1;
207+
color: rgb(0 0 0 / var(--tw-text-opacity));
208+
}
209+
@media (prefers-color-scheme: dark) {
210+
.md\:\[\&\>\*\]\:\(text-black\2c
211+
dark\:\(text-white\2c
212+
hover\:\[\@supports\(color\:green\)\]\:\[\&\:nth-child\(2n\=1\)\]\:text-gray-100\)\)
213+
> * {
214+
--tw-text-opacity: 1;
215+
color: rgb(255 255 255 / var(--tw-text-opacity));
216+
}
217+
@supports (color: green) {
218+
.md\:\[\&\>\*\]\:\(text-black\2c
219+
dark\:\(text-white\2c
220+
hover\:\[\@supports\(color\:green\)\]\:\[\&\:nth-child\(2n\=1\)\]\:text-gray-100\)\):nth-child(2n=1):hover
221+
> * {
222+
--tw-text-opacity: 1;
223+
color: rgb(243 244 246 / var(--tw-text-opacity));
224+
}
225+
}
226+
}
227+
}
228+
`)
229+
})
230+
})
231+
181232
it('should group with variants defined in external plugins', () => {
182233
let config = {
183234
experimental: 'all',

0 commit comments

Comments
 (0)