-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Important modifier doesn't work on @apply
rules for custom utilities and components
#13102
Comments
I have this same issue. I do think this is simply a missing feature, not a bug. Input: @layer components {
.dev {
@apply border border-dashed border-red-600;
}
} <div class="!dev">...</div> Output I wish to have: .\!dev {
border-width: 1px !important;
border-style: dashed !important;
--tw-border-opacity: 1 !important;
border-color: rgb(220 38 38 / var(--tw-border-opacity)) !important
} @MichaelAllenWarner unrelated to this feature request / bug, I see you were |
Yes, probably (and thank you), and to be clear: the "bug" / feature-request affects both utilities and components. (I just picked one for demonstration purposes.) That said, here is another aside: I rarely use |
Hey! No plans to go back and fix this one in v3 I'm afraid, but the good news is this works as expected already in v4.0: https://play.tailwindcss.com/0oUYDWmk4E So going to close this, but thanks for raising regardless. |
What version of Tailwind CSS are you using?
v3.4.1
What build tool (or framework if it abstracts the build tool) are you using?
N/A
What version of Node.js are you using?
v19.8.1
What browser are you using?
Chrome
What operating system are you using?
macOS
Reproduction URL
https://play.tailwindcss.com/N1pmDRsMmo
Describe your issue
This may be intended behavior—if so, apologies for filing this as an issue. I couldn't find any previous discussions or issues about this, though.
The important-modifier doesn't work for
@apply
rules that are part of custom utilities or components. For example, if I've done:then
class="!foo"
will apply thetext-lg
andunderline
rules but without the!important
syntax. The same limitation is true if I instead useaddUtilities()
oraddComponents()
in my Tailwind config, like:On the other hand, any rules for
.foo
declared with normal CSS syntax (or normal CSS-in-JS syntax) will get!important
in theclass="!foo"
case.It would be nice if the important-modifier worked with
@apply
rules in custom utilities and components. The!important
would of course have to go on the actual property-value pairs, which are sometimes nested in at-rules or media queries (with syntax like@apply sm:underline
); I don't know whether that would present a major challenge.In anticipation of the argument that one simply shouldn't use
@apply
in this way:In my opinion, this sort of situation—building new utilities/components from existing ones—is precisely where
@apply
really shines! This technique lets you keep everything "in sync," so that if, for example, the definition oftext-lg
ever changes, then that change cascades to.foo
in my code above. (And you'll even get an error if you try to@apply
something that doesn't exist, which I'd argue is helpful here.) I know that one can use thetheme()
directive to refer to theme-values, but that doesn't let you do things like weave in custom variants with complex selectors (my typical use-cases for this technique are considerably more complicated than the simple example I've given).The text was updated successfully, but these errors were encountered: