-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[v4] variants are not applied to custom classes in utilities layer #14058
Comments
I think this is related to #14044. Not sure why the old logic (all utilities in |
Hey! Yeah this is one of the changes we need to make for v4 because In v3,
I don't want to hijack real CSS features and change their behavior in special Tailwind-specific ways, so we need a new API for this in v4. You should be able to use regular CSS layers in your code without surprising unexpected side effects. One of the reasons we're going with @layer utilities {
h2 > .foo + .bar {
font-weight: bold;
font-size: 20px;
}
} With that rule, we had to make In the v4 API, you're sort of forced to tell Tailwind what the actual "utility" is, and can only pick one: @utility foo {
h2 > & + .bar {
font-weight: bold;
font-size: 20px;
}
} Now we only have to make We're going to work on some code mod tooling in the coming months to try and make this migration as simple as possible though either way 👍 |
Thanks for taking the time to answer! However, I'm still skeptical that the new v4 API is better.
I would argue that those side effects were why most of us put CSS into that utilities layer so they could be used with all variants, only when they were actually used. Otherwise, we could just leave the CSS outside the layer and it would be the same result.
But the new API would not work as regular CSS either. And neither
That is definitely bad and not considered an utility. Maybe instead of trying to make that work, Tailwind could throw an error. Tailwind has a lot of conventions, and requiring utilities to be single class is not big of an ask. |
What version of Tailwind CSS are you using?
v4.0.0-alpha.17
What build tool (or framework if it abstracts the build tool) are you using?
@tailwindcss/[email protected]
What version of Node.js are you using?
v20.12.2
What browser are you using?
Chrome version 126.0.6478.127 (Official Build) (arm64)
What operating system are you using?
macOS 14.5 (23F79)
Reproduction
Describe your issue
I would expect the following style generated, because
.foobar
is within@layer
directive, and should be able to be used with modifiers, according to docs.But there is not. Same with
before:foobar
.The text was updated successfully, but these errors were encountered: