[v3.4.x] Custom variant for elements that are not descendants of @container
breaks
#13370
-
Hi everyone! I have the following situation:
I want to write styles for
What I came up with that worked in v3.3.x was this custom variant: /**
* Register -@ variant
* Use this to match elements that don't have a container ancestor.
* This variant must be put last.
* @example hhover:-@:m-0
*/
addVariant('-@', ({ container }) => {
const newRule = postcss.rule({ selector: '' })
const clonedContainer = container.clone()
clonedContainer.walkRules((rule: { selector: string }) => {
// This will match elements that don't have any ancestor using
// the `@container` utility class
rule.selector = `&:not([class*="@container"] &)`
})
newRule.append(clonedContainer.nodes)
container.removeAll()
container.append(newRule)
}) When used together
Important However, this custom variant breaks after upgrading to v3.4.1! I guess TW changed something internally that might have broken the way I use the
Thanks in advance everyone! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Reproducible code: https://play.tailwindcss.com/wOuW9kA3fp?file=config |
Beta Was this translation helpful? Give feedback.
Because the nature of this variant,
-@
needs to be the last variant so it can capture the full selector and put it in the:not()
pseudo-class.I finally made it work in 3.4.4: