Skip to content
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 @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensure standalone `@tailwindcss/cli` binaries are ignored when scanning for class candidates ([#20139](https://github.com/tailwindlabs/tailwindcss/pull/20139))
- Ensure class candidates are extracted from Twig `addClass(…)` and `removeClass(…)` calls ([#20198](https://github.com/tailwindlabs/tailwindcss/pull/20198))
- Don't crash in the Ruby or Vue preprocessors when scanning files containing invalid UTF-8 bytes ([#19588](https://github.com/tailwindlabs/tailwindcss/pull/19588))
- Allow `@variant` to be used inside `addBase` ([#19480](https://github.com/tailwindlabs/tailwindcss/pull/19480))

### Changed

Expand Down
49 changes: 49 additions & 0 deletions packages/tailwindcss/src/compat/plugin-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,55 @@ describe('addBase', () => {
"
`)
})

test('@variant is replaced inside rules using addBase', async () => {
expect(
await compileCss(
css`
@plugin "my-plugin";
@theme {
--breakpoint-supertiny: 128px;
}
`,
{
loadModule: async () => ({
path: '',
base: '/root',
module: plugin(function ({ addBase }) {
addBase({
':root': {
'@variant supertiny': {
'--PascalCase': '1',
'--camelCase': '1',
'--UPPERCASE': '1',
},
'@variant data-enabled:focus, disabled': {
'--x': '1',
},
},
})
}),
}),
},
),
).toMatchInlineSnapshot(`
"
@layer base {
@media (min-width: 128px) {
:root {
--PascalCase: 1;
--camelCase: 1;
--UPPERCASE: 1;
}
}

:root[data-enabled]:focus, :root:disabled {
--x: 1;
}
}
"
`)
})
})

describe('addVariant', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/tailwindcss/src/compat/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { escape } from '../utils/escape'
import { inferDataType } from '../utils/infer-data-type'
import { segment } from '../utils/segment'
import { toKeyPath } from '../utils/to-key-path'
import { compoundsForSelectors, IS_VALID_VARIANT_NAME, substituteAtSlot } from '../variants'
import {
compoundsForSelectors,
IS_VALID_VARIANT_NAME,
substituteAtSlot,
substituteAtVariant,
} from '../variants'
import { walk, WalkAction } from '../walk'
import type { ResolvedConfig, UserConfig } from './config/types'
import { createThemeFn } from './plugin-functions'
Expand Down Expand Up @@ -110,6 +115,7 @@ export function buildPluginApi({
if (referenceMode) return
let baseNodes = objectToAst(css)
featuresRef.current |= substituteFunctions(baseNodes, designSystem)
featuresRef.current |= substituteAtVariant(baseNodes, designSystem)
let rule = atRule('@layer', 'base', baseNodes)
walk([rule], (node) => {
node.src = src
Expand Down