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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Typography] Cannot customize primary/error color #34290
Comments
@emlai The Typography component does not have it's own So for your use case you can do: <Typography color={`primary${[palette.mode === 'dark' ? 'light' : 'main']}]`}>
Hello world
</Typography>; See |
@ZeeshanTamboli Unfortunately, as per the "context" section in the issue description, that wouldn't work for our use case, since it would require users of our library to specify that condition every time they want to use primary or error colors on Typography. The user should be able to simply specify Would it be possible to fix this in a way that requires no changes from our users, such as adding classes like |
@emlai In that case, you can override the default palette, like: const theme = createTheme({
palette: {
primary: {
main: '#085982', // your custom color
},
error: {
main: '#d40808', // your custom color
},
},
}); And render it like this: function App() {
return (
<ThemeProvider theme={theme}>
<Typography color="primary">Hello World</Typography>
<Typography color="error">Hello World</Typography>
</ThemeProvider>
);
} |
@ZeeshanTamboli Our users are relying on We have successfully customized the color of Ideally |
Ok I think I understand what you mean. Do you mean that you cannot override the default global palette colors since your users are relying on them? You would like to change the color on component level?
The system property is actually more powerful. I came up with a solution for your use case where you can apply the hex value directly on the Typography component I hope it helps you to customize on |
Yes.
We don't re-export MUI components from our library, so our users are importing
It doesn't seem that way to me. Or at least, it's not helping solve this problem. |
I just remembered a fourth way to customize the style (MUI docs): accessing the styleOverrides: {
root: ({ ownerState }) => {
switch (ownerState.color) {
case "primary.main":
return {
color: palette.primary[palette.mode === "dark" ? "light" : "main"],
};
case "error.main":
return {
color: palette.error[palette.mode === "dark" ? "light" : "main"],
};
}
}, We use this for some other components, but unfortunately it doesn't seem to work for I don't think |
I have researched about this issue and found some related discussions about this in #32574 and #32653 (related to Link which inherits Typography). Also looked at #31857. This indeed is a bug. @emlai Thanks for the detailed discussion. I'm re-opening this issue. |
Duplicates
Latest version
Current behavior 馃槸
<Typography color="primary">
doesn't allow customizing the color:color="primary"
doesn't add any classes that we could use for styling.styleOverrides
doesn't support theprimary
orcolorPrimary
key:New component variant has no effect:
Same applies for
color="error"
.Expected behavior 馃
Typography
provides some way to change the color ofcolor="primary"
intopalette.primary[palette.mode === "dark" ? "light" : "main"]
, and same forcolor="error"
.Steps to reproduce 馃暪
https://codesandbox.io/s/brave-spence-5wxolh?file=/demo.js
Context 馃敠
We're maintaining a UI library based on MUI, so we can't fix this at the
<Typography>
call site. So we can't do for example<Typography color={palette.primary[palette.mode === "dark" ? "light" : "main"]}>
.Your environment 馃寧
No response
The text was updated successfully, but these errors were encountered: