mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Allow @variant to be used at the top-level (#16129)
This makes it so `@variant` is replaced at the top level and not just within rules. This also fixes a bug where `@variant` wasn't handled when inside an `@media` at-rule.
This commit is contained in:
parent
7f1d0970c3
commit
4052eb24bf
@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Do not emit `@keyframes` in `@theme reference` ([#16120](https://github.com/tailwindlabs/tailwindcss/pull/16120))
|
||||
- Discard invalid declarations when parsing CSS ([#16093](https://github.com/tailwindlabs/tailwindcss/pull/16093))
|
||||
- Do not emit empty CSS rules and at-rules ([#16121](https://github.com/tailwindlabs/tailwindcss/pull/16121))
|
||||
- Handle `@variant` when at the top-level of a stylesheet ([#16129](https://github.com/tailwindlabs/tailwindcss/pull/16129))
|
||||
|
||||
## [4.0.1] - 2025-01-29
|
||||
|
||||
|
||||
@ -3510,6 +3510,38 @@ describe('@variant', () => {
|
||||
background: white;
|
||||
}
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
@variant landscape {
|
||||
.btn2 {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
.foo {
|
||||
color: red;
|
||||
}
|
||||
@variant landscape {
|
||||
.bar {
|
||||
color: blue;
|
||||
}
|
||||
}
|
||||
.baz {
|
||||
@variant portrait {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media something {
|
||||
@variant landscape {
|
||||
@page {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[],
|
||||
),
|
||||
@ -3522,6 +3554,38 @@ describe('@variant', () => {
|
||||
.btn {
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
@media (orientation: landscape) {
|
||||
:scope:hover .btn2 {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
|
||||
:scope:hover .foo {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@media (orientation: landscape) {
|
||||
:scope:hover .bar {
|
||||
color: #00f;
|
||||
}
|
||||
}
|
||||
|
||||
@media (orientation: portrait) {
|
||||
:scope:hover .baz {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media something {
|
||||
@media (orientation: landscape) {
|
||||
@page {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
}"
|
||||
`)
|
||||
})
|
||||
|
||||
@ -244,6 +244,11 @@ async function parseCss(
|
||||
return WalkAction.Stop
|
||||
}
|
||||
})
|
||||
|
||||
// No `@slot` found, so this is still a regular `@variant` at-rule
|
||||
if (node.name === '@variant') {
|
||||
variantNodes.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,6 +434,13 @@ async function parseCss(
|
||||
replaceWith(node.nodes)
|
||||
}
|
||||
|
||||
walk(node.nodes, (node) => {
|
||||
if (node.kind !== 'at-rule') return
|
||||
if (node.name !== '@variant') return
|
||||
|
||||
variantNodes.push(node)
|
||||
})
|
||||
|
||||
return WalkAction.Skip
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user