Skip to content

Commit 98359be

Browse files
authored
Ensure .group and .peer are prefixed when using the prefix(…) option (#15174)
This PR fixes an issue where the `.group` and `.peer` classes didn't get prefixed if you are using the `prefix(…)` option. Before this change, `tw:group-hover:flex`, generated: ```css .tw\\:group-hover\\:flex { &:is(:where(.group):hover *) { @media (hover: hover) { display: flex; } } } ``` But now it generates: ```css .tw\\:group-hover\\:flex { &:is(:where(.tw\\:group):hover *) { @media (hover: hover) { display: flex; } } } ``` Or as a diff, it might be more clear: ```diff .tw\\:group-hover\\:flex { - &:is(:where(.group):hover *) { + &:is(:where(.tw\\:group):hover *) { @media (hover: hover) { display: flex; } } } ``` Fixes: #15172
1 parent bd43d63 commit 98359be

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
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 `.group` and `.peer` are prefixed when using the `prefix(…)` option ([#15174](https://github.com/tailwindlabs/tailwindcss/pull/15174))
1113

1214
## [4.0.0-beta.2] - 2024-11-22
1315

packages/tailwindcss/src/prefix.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,35 @@ test('utilities must be prefixed', async () => {
1717
let compiler = await compile(input)
1818

1919
// Prefixed utilities are generated
20-
expect(compiler.build(['tw:underline', 'tw:hover:line-through', 'tw:custom']))
21-
.toMatchInlineSnapshot(`
20+
expect(
21+
compiler.build([
22+
'tw:underline',
23+
'tw:hover:line-through',
24+
'tw:custom',
25+
'tw:group-hover:flex',
26+
'tw:peer-hover:flex',
27+
]),
28+
).toMatchInlineSnapshot(`
2229
".tw\\:custom {
2330
color: red;
2431
}
2532
.tw\\:underline {
2633
text-decoration-line: underline;
2734
}
35+
.tw\\:group-hover\\:flex {
36+
&:is(:where(.tw\\:group):hover *) {
37+
@media (hover: hover) {
38+
display: flex;
39+
}
40+
}
41+
}
42+
.tw\\:peer-hover\\:flex {
43+
&:is(:where(.tw\\:peer):hover ~ *) {
44+
@media (hover: hover) {
45+
display: flex;
46+
}
47+
}
48+
}
2849
.tw\\:hover\\:line-through {
2950
&:hover {
3051
@media (hover: hover) {

packages/tailwindcss/src/variants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ export function createVariants(theme: Theme): Variants {
518518
// Name the group by appending the modifier to `group` class itself if
519519
// present.
520520
let variantSelector = variant.modifier
521-
? `:where(.group\\/${variant.modifier.value})`
522-
: ':where(.group)'
521+
? `:where(.${theme.prefix ? `${theme.prefix}\\:` : ''}group\\/${variant.modifier.value})`
522+
: `:where(.${theme.prefix ? `${theme.prefix}\\:` : ''}group)`
523523

524524
let didApply = false
525525

@@ -570,8 +570,8 @@ export function createVariants(theme: Theme): Variants {
570570
// Name the peer by appending the modifier to `peer` class itself if
571571
// present.
572572
let variantSelector = variant.modifier
573-
? `:where(.peer\\/${variant.modifier.value})`
574-
: ':where(.peer)'
573+
? `:where(.${theme.prefix ? `${theme.prefix}\\:` : ''}peer\\/${variant.modifier.value})`
574+
: `:where(.${theme.prefix ? `${theme.prefix}\\:` : ''}peer)`
575575

576576
let didApply = false
577577

0 commit comments

Comments
 (0)