-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[material-ui] Opt-in support for @layer
to fix Tailwind v4 integration
#44700
Comments
I agree with this to fix the integration with Tailwind v4, keeping in mind the requirements:
|
@layer
@layer
to fix Tailwind v4 integration
@layer
to fix Tailwind v4 integration@layer
to fix Tailwind v4 integration
I don't know if this is 100% related to the topic of the issue, but I was having some issues when using /* index.css */
@import "tailwindcss" important; /* <==== just add the important keyword */
/* other project styles */ Although simple, it is not the same as the previous |
|
Nice! Thanks for the fix. I knew there was some way to mark layer as important, but couldn't find it on MDN somehow. You don't have to import all of tailwindcss parts. Based on the instructions here (https://tailwindcss.com/docs/preflight), I'm doing this: @layer theme, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/utilities.css" layer(utilities) important; I just put |
@HasanMothaffar @mrdjohnson @Malivuca Please see this repo for proper configuration. Repo: https://github.com/siriwatknp/mui6-tailwind4-vite Summary: set up CSS layer for Material UI to be |
Demo
Repo: https://github.com/siriwatknp/mui6-tailwind4-vite
Preview: https://siriwatknp.github.io/mui6-tailwind4-vite/
Motivation
Tailwind integration
The current Material UI v6 is hard to use with CSS utilities like Tailwind CSS because some components have higher CSS specificity than (0,1,0) so Tailwind CSS could not be used without
!important
.Also, Tailwind v4 (will be stable soon) is using native CSS layer so Material UI won't be able to override it without a configurable layer.
Here is the issue using Material UI v6 + Tailwind v4 (beta). The
text-2xl
cannot override the Typography base styles.Different override behavior when using CSS variables
Another issue is the behavior change when transition from dynamic CSS using
theme.palette.mode
to CSS variables paradigm (static CSS). Thesx
prop cannot override the:where()
because Emotion always append:where()
at the end of the styles.Requirements
Options
1. A custom stylis plugin for single layer
Based on this solution, this will capture emotion styles into a single layer, likely named
@layer mui
.I think this is a simplest solution that works really well. It will fix the Tailwind v4 integration but it won't fix the "Different override behavior when using CSS variables" because all Material UI styles are in the same layer.
2. Add flag to the theme for multiple layers
To solve "Different override behavior when using CSS variables", the sx styles must be in a different layer so that it overrides the styles of the component regardless of selector's specificity.
A custom stylis plugin (option 1) is not possible to support multiple layers, so the layer has to be created from the
styleFunctionSx
.Feel free to share other possible options that we could do.
Search keywords:
The text was updated successfully, but these errors were encountered: