material-ui: Can't use Joy and Material UI together
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
Hello. I’m currently trying out and working on migrating parts of my project to the new vars system, and I setup the experimental CssVarsProvider from the standard Mui Package, and at the same time I’ve loaded Joy to try to utilize the new Aspect Ratio and Card components, however, it seems the CssVarsProvider is having some issues.
The issue seems to be with the news theme vars. When I wrap the app and try to load a card it throws can't read undefined of soft or can't read undefined of md. I checked the theme object and it seems that the vars object is constructed fine although it lacks the vars for the new Joy patterns. (The vars aren’t created with the Joy CssVarsProvider either).
I currently use a monorepo, so I have my apps folder and pkgs folder, and the whole Mui theme component that wraps my project is there. I have the CSS vars component in there, it also takes a custom theme object that’s built with experimental_extendTheme. Oddly enough if I wrap the components I want to render directly with CssVarsProvider from Joy it works fine, but if I wrap the whole project or a parent in a different file, it fails.
Expected behavior 🤔
Wrapping the project from the root should allow the components to work anywhere.
Steps to reproduce 🕹
I used siriwatknp repo for reference. The document and app setup is the same with the exception of the custom theme object I pass into the vars component that’s built with extendTheme https://github.com/siriwatknp/mui-joy/tree/main/pages
Context 🔦
No response
Your environment 🌎
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (8 by maintainers)
For anyone that comes across this issue, we just published a doc that shows how to use both libraries together.
https://mui.com/joy-ui/guides/using-joy-ui-and-material-ui-together/
This guide is now at: https://mui.com/joy-ui/integrations/material-ui/
Are Mui and Mui Joy compatible? I wouldn’t think they would conflict but is that possible?
Btw I forgot to mention it in my last message. Joy is looking great! From the stuff I’ve seen so far I think it’s going to be a great new package!
theme.txt I was using joy theme with a little material theme , and with a new project , following https://mui.com/joy-ui/guides/using-joy-ui-and-material-ui-together/ but I can’t load shouldSkipGeneratingVar from @mui/material/styles , as matter of fact there is no more export for that in the lib . and the https://codesandbox.io/s/joy-ui-feat-material-ui-k86j2j?file=/demo.tsx is buggy too, I use jsx and not typescript. my package.json is : “@mui/icons-material”: “^5.11.11”, “@mui/joy”: “5.0.0-alpha.70”, “@mui/material”: “^5.11.12”, “@mui/styles”: “^5.11.12”, “@mui/utils”: “^5.11.12”,
@Rafcin @echarles @Michael-Davies @persunde Thanks for the interest in using Joy UI! really appreciate it.
I now see the use case for using Joy with Material UI and worked on #33379 to make both of them compatible in an intuitive way.
Here is the code example (which will be released next week): https://codesandbox.io/s/joy-cra-typescript-forked-c9csds?file=/src/App.tsx
NOTE that this is just a workaround for using Joy UI because of small supported components. Once Joy is mature, we are not encouraged to use both Joy UI and Material UI in the same project because you would have 2 design guidelines in the same application (I don’t think this is a good practice but I am also happy to be proven wrong 😁).
Hey @Rafcin, we’re glad to see some early interest in using Joy UI-so cool! Getting to your question:
I’d say they should be. However, we haven’t yet prepared any documentation for that, nor have we figured out the edge cases (some that you’re finding out now) for them to co-exist. As I figure that this use case will probably be a common one (folks that are used to Material UI willing to test Joy UI out), we definitely will look into creating proper guidance to assist you.
For the time being, I guess @siriwatknp will be able to sort some details. By the end of Q3, we hope to have Joy UI in a much more solid place, and hopefully with this process documented!
Hi @danilo-leal, thanks for your response!
I actually managed to get something working by just duplicating the theme on both providers.
The only caveat is that the color mode setting for the MUI X components doesn’t seem to work when running it locally on Windows (but it works fine when built and deployed).
@danilo-leal sounds good I’ll open one up!
Thank you @siriwatknp!! I’ll give this a shot and see how it works!
For my main project, I’ve taken Aspect Ratio & Card and added them to my own set of components that use MUI by just rewriting it and taking out the Joy aspects of it. Works super well for now.
Also @danilo-leal @siriwatknp I wanted to ask, would it be alright if I proposed a feature request for a carousel component? After looking at card and aspect ratio for a while I’ve been writing just some random test components and I’ve started to make a scroll snap carousel with Tanstacks react-virtual pkg. I know standard MUI doesn’t have this but could Joy use a carousel component?
@Rafcin Not sure how you got the repo but that is outdated, sorry for that.
Absolutely yes, both of them are powered by the same engine. However, there is some gotcha that needs to be aware of:
After #33379 is merged, here is how to use Joy with Material UI.
So I’ve created an experimental branch for my site that will run Joy, and once it’s a little more fleshed out ill convert everything to Joy. In the meantime, I’ve migrated to using the experimental vars in MUI and asked for Aspect Ratio and Card, I took the components from Joy and rewrote them partially to work with standard MUI. I removed the variant and color props and added some of my own extra props for them and it works like a charm.
A workaround that seems to be working for me is to use
Experimental_CssVarsProviderwhen I have a Material UI component that I need to use. YMMV. An example:I am trying to have a application which mixes the standard mui (material-ui) and the new joy components. To do that, I wrap the mui StyledEngineProvider/CssVarsProvider into the mui ThemeProvider to finally receive undefined exception when I try to access the mui (material-ui) theme.
This lead me to think that both are incompatible for now, which is not the best experience from 2 libraries coming from the same project.