-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Cannot read properties of undefined (reading 'main') when defining custom color variants #29964
Comments
It is unclear what you have tried. Could you share a codesandbox? Yes, the color needs to be defined in the palette, as the
will be defined. If you define the color in the palette, everything should work out of the box. |
Duplicate of #13875 |
@mnajdova thanks for your answer ! As mentioned in my initial post, I have tried adding the color to the palette but I still get the issue: const theme = createTheme({
palette: {
hello: {
main: 'red',
},
} as any,
// ...
}); I have to use |
You need to use module augmentation if you want to add new things in the theme - https://mui.com/customization/theming/#custom-variables Without a reproduction, I can't do anything. |
I'll put up a sandbox, just a sec 😄 |
Ok, it seems the sandbox is actually working 😓 There must be something wrong with my local setup, greatest apologies. |
@gempain Did you find the solution? I am having the same issue when trying to add a custom color to the theme. |
Duplicates
Latest version
Current behavior 😯
When adding new component variants, say for
Button
, I am allowed to create variants by declaringButtonPropsColorOverrides
and then defining the correspondingvariants
in a custom theme, in thecomponents.MuiButton.variants
property. While this works for theButton.variant
property, it doesn't forButton.color
. After setting my variants, when I use them in code, I get:Expected behavior 🤔
I would expect the above error not to happen, since defining variants for the
variant
property (instead ofcolor
) does not create this issue.I suspect that MUI tries to find my custom color in the theme palette, hence looking for
theme.palette.myColor.main
is undefined.Steps to reproduce 🕹
Simply use this component in a React app:
I tried defining the color in the theme platte, but no luck:
Context 🔦
I'm trying to add additional colors alongside
primary
,secondary
, etc, without creating a custom component. I want to keep using MUI's Button, I don't want to create a proxy component as this is for a shared theme package and I want my users to keep importingButton
from@mui/material
instead of@my-org/my-theme
.I looked at #14185 but it's not solving my problem.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: