-
-
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
TypeError: color.charAt is not a function #16341
Comments
Please provide a reproducible example. I would also check your imports and make sure they are less than 2 path levels. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For anyone else with this issue, I'd just done something dumb and assigned a primary text color like this: |
Thanks for the feedback. It sounds like we should be able to improve the error message :). The current one is cryptic. |
The comments marked off-topic are what I used to solve this same issue. |
@Mugungaman Do you have a reproduction for the error? How can we reproduce it? |
This recreates, where 'content' is a style applied to a component... App.js: const theme = createMuiTheme({
...,
content: {
padding: 25,
objectFit: "cover"
}
}); Child component: const styles = theme => ({
...theme
}); <CardContent className={classes.content}> ...and this fixes it, wrapping the style name 'content' in a spreadIt object: App.Js: const theme = createMuiTheme({
...,
spreadIt: {
content: {
padding: 25,
objectFit: "cover"
}
}
}); Child component: const styles = theme => ({
...theme.spreadIt
}); <CardContent className={classes.content}> |
I have no idea how developers are creating this issue. Let's close until we have a full reproduction. |
@oliviertassinari I have reproduced this. Please check this sandbox https://codesandbox.io/s/material-uiissues16341-7mfwk |
I have figured it out. The problem was due to using the colors wrongly in theme. The following code causes the error.
The correct way to use colors in theme is as follows: (Notice that value of primary should be the color and not the main key of primary object).
To be honest the official documentation does not consolidate all the aspects of customizing theme. It is broken down into different pages. I guess it causes some confusion. After getting familiar with the material-ui, I was able to spot this mistake. |
"@material-ui/core": "^4.9.5", I have same issue. In App.js I have
In child component, I have
and here is error |
this doesn't fix issue for me |
@gota1993 Try to reproduce it at https://codesandbox.io/ and share it so that others can debug it. |
Top voted answer for this question fixed it for me. |
i just run npm install @material-ui/[email protected] and problem was solved |
Thank you, its work! |
I was also facing this problem but problem solved when i put my custom styling in an object and other MUIStyling in a separate object such as palete and much more I have a login and signup form for which i have made styling and this styling is inside loginSignupStyle Object look at this example {
palette:{
primary:{
light:"#33C9DC",
main:"#00BCD4",
dark:"#008394",
contrastText:"#fff"
},
secondary:{
light:"#FF6333",
main:"#FF3D00",
dark:"#B22A00",
contrastText:"#fff"
}
},
loginSignupStyle:{
image:{
margin:"10px auto"
},
form:{
textAlign:"center"
},
textFeild:{
margin:"10px auto"
},
loginBtn:{
marginTop:10,
position:"relative"
},
errorText:{
color:"red",
fontSize:"0.8rem",
display:"block",
margin:"10px auto"
},
account:{
display:"block",
marginTop:10
},
loading:{
position:"absolute"
}
}
} It worked for me |
So after reading all of this it seems there is no way to have nested objects inside of a palette? i.e. the following is impossible: palette: {
notifications: {
error: {
main: '#C42014',
dark: '#CC4137',
light: '#DB7A73',
},
success: {
main: '#111',
dark: '#222',
light: '#333',
},
},
} so I have to do the following ? palette: {
notificationError: {
main: '#C42014',
dark: '#CC4137',
light: '#DB7A73',
},
notificationSuccess: {
main: '#111',
dark: '#222',
light: '#333',
},
} |
After that, get it in child component like this way
It worked for me |
I have some warning like this:
TypeError: color.charAt is not a function
decomposeColor
node_modules/@material-ui/core/esm/styles/colorManipulator.js:125
lighten
node_modules/@material-ui/core/esm/styles/colorManipulator.js:270
Array.onUpdate
node_modules/jss-plugin-rule-value-function/dist/jss-plugin-rule-value-function.esm.js:46
The text was updated successfully, but these errors were encountered: