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
[IconButton] Custom non-palette color causes TypeError #33054
Comments
The customization capability is not complete. I marked this as an enhancement. The fix can use optional chaining like in createTheme({
components: {
MuiIconButton: {
root: ({ ownerState, theme }) => ({
...ownerState.color === 'textPrimary' && {
// your style
}
})
}
}
}) |
Ah that explains it. I worked around it by passing the color to the icon component instead, and augmenting <IconButton>
<CloseIcon color="textPrimary" />
</IconButton> |
Is this issue open to working on? |
@Shubhamchinda I don't think it's being worked on, so feel free to take it. Thank you! |
Great, thanks. I'll take this. |
Any progress? Would love to implement this PR |
@geraldaddey Give me a day, and I'll submit a PR. |
Is this issue still open to work on? Would like to work on it |
@shachargiladi 4 weeks since the last response, so I think it was abandoned. I'd say go ahead! |
Hi is anyone working one this .I'd like to take it. @emlai |
Hi is anyone working one this? I'd like to take it. |
Hi anyone still working on this? I'd like to take it. @emlai @cyberGHostJs @hilalsidhic |
Hey, doesn't seems to be an issue for me 馃 . I was thinking to pick this up, but it didn't reproduce for me. |
My bad, reproducible. @rizamoyi have you started work on it or are you working on it? If not, I can pick this up. |
@kushagra010 I started working on it. |
is this issue still on or can take it over and work on it? |
@harsh5902 you can take it over |
I have solved the this problem and created a pull request, please do review it. |
@harsh5902 Why was the PR closed? |
The PR to fix this issue should:
@ZeeshanTamboli if you are available, this could be one to pick up. |
I am on a bit of a break currently and won't be working next 3-4 weeks much effectively. If somebody else wants to take a look till then, please go ahead. |
this is working fine i guess, i just tested it.
and add these lines for IconButton
these enabling the createTheme to be aware of these colors, then you need to provide the implementation in the theme that would be passed in the themeProvider, like so
because we do want to let the mui know the values of the color. @emlai the problem for you might be that you're not writing up the color prop in createTheme for palette |
@the-mgi Yes, if your palette has the exact same key as the specified But we're intending to use |
got it. thanks. |
@TCsTheMechanic Workaround for IconButton is to pass the |
@emlai also doesn't work |
@TCsTheMechanic Did you augment the typings: declare module "@mui/material/SvgIcon" {
interface SvgIconPropsColorOverrides {
"textColor.light": true;
}
} |
@emlai still nothing, I'm using |
I am not sure what is the issue here. Custom color does work with typescript with module augmentation and can be augmented. If the custom color is not defined in the palette it will crash. |
That is exactly the issue. In our use case the custom color is not in the palette. The same custom color works fine for the icon component. See the original issue description. |
Then what styles are you applying with the custom color? Why are you calling it with
Yes it works, but if it is not in the palette why should it unnecessarily calculate
In it you need Am I missing something here? Please enlighten me. |
@ZeeshanTamboli The issue is solid. From my understanding, it is intended that the This is not about the color value (that's the developers' decision), not our. We just provide a way to extend the color. This PR will fix the issue: #34521 |
@siriwatknp Hello, it looks like issue still occurs for me. It's working perfectly with
( I use latest libs versions:
I tried to reinstall dependencies by removing |
Pleasr share a Code sandbox that reproduces the issue. |
@siriwatknp Facing same issue for icons imported from '@icons-material'. module augmentation is not working for |
why is the issue closed if the issue is reproducible? |
@nikolay-bennie Please provide a reproduction with the latest Material UI version. |
Hi @siriwatknp @ZeeshanTamboli I also got this issue
To reproduce:
Note: The "custom Here is the code sandbox, try to access I think I did the config correctly, didn't I? |
Duplicates
Latest version
Current behavior 馃槸
When I augment
IconButton
with new colors that don't exist in the palette:and then try to use these colors:
My app crashes with:
at the following location:
material-ui/packages/mui-material/src/IconButton/IconButton.js
Line 78 in dec32b3
Expected behavior 馃
IconButton
doesn't throw TypeError when using custom color. Instead it handles it safely, likeSvgIcon
:material-ui/packages/mui-material/src/SvgIcon/SvgIcon.js
Line 54 in dec32b3
Steps to reproduce 馃暪
No response
Context 馃敠
We intend for
color="textPrimary"
(orcolor="text.primary"
, both are fine) to use thetext.primary
palette color.Workaround: pass the color to the icon component instead and augment
SvgIconPropsColorOverrides
typings:Your environment 馃寧
No response
The text was updated successfully, but these errors were encountered: