-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
createGenerateClassName #28550
Comments
@mnajdova Do we provide that option? |
We haven't considered this in v5. Although I want to mention that it was something provided by the I think it's worth adding it long term, especially when we would need to support multiple design systems. |
@siriwatknp should we mention this in the migration guide? |
@mnajdova & @siriwatknp This option has been very useful for our team. Because we have different microservice UI projects integrated into one big orchestrator project. This helps us avoid CSS class names collision and keep unique across other microservice projects which use Material UI. Also, It's a good idea to mention the migration guide, so at least those who are using this will know there is a breaking change when updated to Material UI v5. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
It is not supported in v5 but I think it is worth to do it to preserve what v4 can do. Currently, the global classNames generated in the components are from utility function // prefix is setup somewhere at the root of app
import { styled } from '@mui/material/styles';
import Button, { buttonClasses } from '@mui/material/Button';
const StyledButton = styled(Button)`
.${buttonClasses.root}: { // buttonClasses.root should be '$prefix-MuiButton-root'
...
}
` With this constrain, I think we can create a global config that can be setup before the App is called. then the // usually index.js
import { GlobalConfig } from '@mui/material';
GlobalConfig.setup({ classNamePrefix: 'myapp' })
ReactDOM.render(<App />, ...) Here is my POC. siriwatknp@6e40bcc. The benefit of this approach is that the component does not need to know how classname is generated, that's why the change in my POC is very small. However, if we use other approach like context or theme, we will need to touch all of the existing components.
What's next?
|
@siriwatknp Thanks a lot, 'cause we have the same situation as in the @smora-gh 's comment #28550 (comment) |
@siriwatknp could you open a PR for the change? We could add it under One thing to keep in mind is that we probably want to keep the global pseudo classes that we are adding under two names 'Mui-disabled |
@siriwatknp Thank you for the fix. But one issue I see with Box Component. Prefix is not added to Box Component. Attached screenshot below. Any work around you suggest? Just in case adding screenshot without Mui replace. Above was with replacing Mui with Foo |
will open a PR to fix it. |
@siriwatknp I see one issue with Grid Container and Grid Item components. CSS specificity is not passed to child. Can you pls help. Issue with ToggleButtonGroup same as above. |
Please open an issue with reproduction in codesandbox, so that we can track and other people can help. |
@smora-gh It sounds like you are looking for emotion-js/emotion#2210. With Material UI v5 and |
@oliviertassinari we haven't upgraded to styled components. All our components are still using JSS for styling. @siriwatknp I did add the |
Please open another issue with reproduction. |
Any news on this? I am using microsites and without createGenerateClassName the styles overlap with each other. The unstable_ClassNameGenerator works for microsites, but not for Storybook libraries for example, and this causes a lot of overlapping styles on my code. Will you fix this at some moment? Or do I need to continue using material v4? |
Please open a new issue with reproduction. |
@smora-gh Then you can use the same API as in v4, I'm adding the As a general rule, I don't think that it's because problem A was fixed with solution X on version v4 and that it no longer works that we need to reapply solution X in v5. Maybe there is already a solution to the problem with emotion that is different than with JSS. For instance, in the case of @smora-gh maybe it's that there are v4 and v5 components mounted on the same page, and the app is not configured as in https://mui.com/x/react-data-grid/migration-v4/#using-mui-core-v4-with-v5. |
In Mui-v4, createGenerateClassName's seed option was prefixed to all material-ui components. But with mui-v5 seed doesn't prefix.
This is the current behavior in mui- v5
This is the expected behavior. This works fine in v4
The text was updated successfully, but these errors were encountered: