Skip to content

Commit 8b4a2a6

Browse files
Change dark selector so @apply works correctly with pseudo elements (#13379)
* Change dark selector so `@apply` hoists pseudo elements properly * Update tests * Update changelog
1 parent 97607f1 commit 8b4a2a6

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Fix missing `xx-large` and remove double `x-large` absolute size ([#13324](https://github.com/tailwindlabs/tailwindcss/pull/13324))
2222
- Don't error when encountering nested CSS unless trying to `@apply` a class that uses nesting ([#13325](https://github.com/tailwindlabs/tailwindcss/pull/13325))
2323
- Ensure that arbitrary properties respect `important` configuration ([#13353](https://github.com/tailwindlabs/tailwindcss/pull/13353))
24+
- Change dark mode selector so `@apply` works correctly with pseudo elements ([#13379](https://github.com/tailwindlabs/tailwindcss/pull/13379))
2425

2526
## [3.4.1] - 2024-01-05
2627

src/corePlugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export let variantPlugins = {
270270
addVariant('dark', selector)
271271
} else if (mode === 'class') {
272272
// Old behavior
273-
addVariant('dark', `:is(${selector} &)`)
273+
addVariant('dark', `&:is(${selector} *)`)
274274
}
275275
},
276276

tests/apply.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -2212,3 +2212,40 @@ test('applying user defined classes with nested CSS should result in an error',
22122212
`)
22132213
})
22142214
})
2215+
2216+
test('applying classes with class-based dark variant to pseudo elements', async () => {
2217+
let config = {
2218+
darkMode: 'class',
2219+
content: [],
2220+
}
2221+
2222+
let input = css`
2223+
::-webkit-scrollbar-track {
2224+
@apply bg-white dark:bg-black;
2225+
}
2226+
::-webkit-scrollbar-track:hover {
2227+
@apply bg-blue-600 dark:bg-blue-500;
2228+
}
2229+
`
2230+
2231+
let result = await run(input, config)
2232+
2233+
expect(result.css).toMatchFormattedCss(css`
2234+
::-webkit-scrollbar-track {
2235+
--tw-bg-opacity: 1;
2236+
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
2237+
}
2238+
:is(.dark *)::-webkit-scrollbar-track {
2239+
--tw-bg-opacity: 1;
2240+
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
2241+
}
2242+
::-webkit-scrollbar-track:hover {
2243+
--tw-bg-opacity: 1;
2244+
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
2245+
}
2246+
:is(.dark *)::-webkit-scrollbar-track:hover {
2247+
--tw-bg-opacity: 1;
2248+
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
2249+
}
2250+
`)
2251+
})

tests/dark-mode.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ it('should be possible to use the darkMode "class" mode', () => {
1616
return run(input, config).then((result) => {
1717
expect(result.css).toMatchFormattedCss(css`
1818
${defaults}
19-
:is(.dark .dark\:font-bold) {
19+
.dark\:font-bold:is(.dark *) {
2020
font-weight: 700;
2121
}
2222
`)
@@ -39,7 +39,7 @@ it('should be possible to change the class name', () => {
3939
return run(input, config).then((result) => {
4040
expect(result.css).toMatchFormattedCss(css`
4141
${defaults}
42-
:is(.test-dark .dark\:font-bold) {
42+
.dark\:font-bold:is(.test-dark *) {
4343
font-weight: 700;
4444
}
4545
`)
@@ -133,7 +133,7 @@ it('should support the deprecated `class` dark mode behavior', () => {
133133

134134
return run(input, config).then((result) => {
135135
expect(result.css).toMatchFormattedCss(css`
136-
:is(.dark .dark\:font-bold) {
136+
.dark\:font-bold:is(.dark *) {
137137
font-weight: 700;
138138
}
139139
`)
@@ -153,7 +153,7 @@ it('should support custom classes with deprecated `class` dark mode', () => {
153153

154154
return run(input, config).then((result) => {
155155
expect(result.css).toMatchFormattedCss(css`
156-
:is(.my-dark .dark\:font-bold) {
156+
.dark\:font-bold:is(.my-dark *) {
157157
font-weight: 700;
158158
}
159159
`)
@@ -181,7 +181,7 @@ it('should use legacy sorting when using `darkMode: class`', () => {
181181
--tw-text-opacity: 1;
182182
color: rgb(187 247 208 / var(--tw-text-opacity));
183183
}
184-
:is(.dark .dark\:text-green-100) {
184+
.dark\:text-green-100:is(.dark *) {
185185
--tw-text-opacity: 1;
186186
color: rgb(220 252 231 / var(--tw-text-opacity));
187187
}

0 commit comments

Comments
 (0)