Skip to content

Commit 0b5bfc8

Browse files
Remove class prefix in arbitrary variant that is used multiple times (#8992)
* Remove prefix in multi-used arbitrary variant * Update changelog Co-authored-by: Jordan Pittman <[email protected]>
1 parent c6bac2d commit 0b5bfc8

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

CHANGELOG.md

+3-1
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+
- Don’t prefix classes within reused arbitrary variants ([#8992](https://github.com/tailwindlabs/tailwindcss/pull/8992))
1113

1214
## [3.1.7] - 2022-07-29
1315

src/lib/generateRules.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ function applyVariant(variant, matches, context) {
129129
}
130130

131131
let args
132-
let isArbitraryVariant = false
133132

134133
// Find partial arbitrary variants
135134
if (variant.endsWith(']') && !variant.startsWith('[')) {
@@ -145,8 +144,6 @@ function applyVariant(variant, matches, context) {
145144
return []
146145
}
147146

148-
isArbitraryVariant = true
149-
150147
let fn = parseVariant(selector)
151148

152149
let sort = Array.from(context.variantOrder.values()).pop() << 1n
@@ -303,7 +300,7 @@ function applyVariant(variant, matches, context) {
303300
...meta,
304301
sort: variantSort | meta.sort,
305302
collectedFormats: (meta.collectedFormats ?? []).concat(collectedFormats),
306-
isArbitraryVariant,
303+
isArbitraryVariant: isArbitraryValue(variant),
307304
},
308305
clone.nodes[0],
309306
]

tests/arbitrary-variants.test.js

+49
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,52 @@ test('classes in arbitrary variants should not be prefixed', () => {
566566
`)
567567
})
568568
})
569+
570+
test('classes in the same arbitrary variant should not be prefixed', () => {
571+
let config = {
572+
prefix: 'tw-',
573+
content: [
574+
{
575+
raw: `
576+
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should not be red</div>
577+
<div class="foo">
578+
<div class="[.foo_&]:tw-text-red-400 [.foo_&]:tw-bg-white">should be red</div>
579+
</div>
580+
<div class="[&_.foo]:tw-text-red-400 [&_.foo]:tw-bg-white">
581+
<div>should not be red</div>
582+
<div class="foo">should be red</div>
583+
</div>
584+
`,
585+
},
586+
],
587+
corePlugins: { preflight: false },
588+
}
589+
590+
let input = `
591+
@tailwind utilities;
592+
`
593+
594+
return run(input, config).then((result) => {
595+
expect(result.css).toMatchFormattedCss(css`
596+
.foo .\[\.foo_\&\]\:tw-bg-white {
597+
--tw-bg-opacity: 1;
598+
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
599+
}
600+
601+
.foo .\[\.foo_\&\]\:tw-text-red-400 {
602+
--tw-text-opacity: 1;
603+
color: rgb(248 113 113 / var(--tw-text-opacity));
604+
}
605+
606+
.\[\&_\.foo\]\:tw-bg-white .foo {
607+
--tw-bg-opacity: 1;
608+
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
609+
}
610+
611+
.\[\&_\.foo\]\:tw-text-red-400 .foo {
612+
--tw-text-opacity: 1;
613+
color: rgb(248 113 113 / var(--tw-text-opacity));
614+
}
615+
`)
616+
})
617+
})

0 commit comments

Comments
 (0)