Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dark selector so @apply works correctly with pseudo elements #13379

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix missing `xx-large` and remove double `x-large` absolute size ([#13324](https://github.com/tailwindlabs/tailwindcss/pull/13324))
- Don't error when encountering nested CSS unless trying to `@apply` a class that uses nesting ([#13325](https://github.com/tailwindlabs/tailwindcss/pull/13325))
- Ensure that arbitrary properties respect `important` configuration ([#13353](https://github.com/tailwindlabs/tailwindcss/pull/13353))
- Change dark mode selector so `@apply` works correctly with pseudo elements ([#13379](https://github.com/tailwindlabs/tailwindcss/pull/13379))

## [3.4.1] - 2024-01-05

Expand Down
2 changes: 1 addition & 1 deletion src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export let variantPlugins = {
addVariant('dark', selector)
} else if (mode === 'class') {
// Old behavior
addVariant('dark', `:is(${selector} &)`)
addVariant('dark', `&:is(${selector} *)`)
}
},

Expand Down
37 changes: 37 additions & 0 deletions tests/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2212,3 +2212,40 @@ test('applying user defined classes with nested CSS should result in an error',
`)
})
})

test('applying classes with class-based dark variant to pseudo elements', async () => {
let config = {
darkMode: 'class',
content: [],
}

let input = css`
::-webkit-scrollbar-track {
@apply bg-white dark:bg-black;
}
::-webkit-scrollbar-track:hover {
@apply bg-blue-600 dark:bg-blue-500;
}
`

let result = await run(input, config)

expect(result.css).toMatchFormattedCss(css`
::-webkit-scrollbar-track {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
:is(.dark *)::-webkit-scrollbar-track {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
::-webkit-scrollbar-track:hover {
--tw-bg-opacity: 1;
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
}
:is(.dark *)::-webkit-scrollbar-track:hover {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
`)
})
10 changes: 5 additions & 5 deletions tests/dark-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ it('should be possible to use the darkMode "class" mode', () => {
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
:is(.dark .dark\:font-bold) {
.dark\:font-bold:is(.dark *) {
font-weight: 700;
}
`)
Expand All @@ -39,7 +39,7 @@ it('should be possible to change the class name', () => {
return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
${defaults}
:is(.test-dark .dark\:font-bold) {
.dark\:font-bold:is(.test-dark *) {
font-weight: 700;
}
`)
Expand Down Expand Up @@ -133,7 +133,7 @@ it('should support the deprecated `class` dark mode behavior', () => {

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

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
:is(.my-dark .dark\:font-bold) {
.dark\:font-bold:is(.my-dark *) {
font-weight: 700;
}
`)
Expand Down Expand Up @@ -181,7 +181,7 @@ it('should use legacy sorting when using `darkMode: class`', () => {
--tw-text-opacity: 1;
color: rgb(187 247 208 / var(--tw-text-opacity));
}
:is(.dark .dark\:text-green-100) {
.dark\:text-green-100:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(220 252 231 / var(--tw-text-opacity));
}
Expand Down
Loading