-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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] iconButtonClasses
does not contain classes for colorError
, colorInfo
, etc.
#33615
Comments
@lindapaiste Thanks for the detailed issue. Yes, some color properties are missing in When you said looking at the props directly, I think you mean something along these lines with the styled API https://codesandbox.io/s/upbeat-heyrovsky-he993o. Note that this approach is more scalable as the classes like |
iconButtonClasses
does not contain classes for colorError
, colorInfo
, etc.iconButtonClasses
does not contain classes for colorError
, colorInfo
, etc.
Can you provide a codesandbox with example how you are going to use the exisisting colorInherit or colorPrimary or colorSecondary please ? Use this codesandbox to prepare sample code |
Is anyone still working on this issue? If not, can I take it? |
@PunitSoniME That issue is for Chip component, this one is for IconButton. |
oh my bad, sorry 馃槂 @Zetta56 you can take it, if you are not taking please let me know, I will pick this up |
Yes, that's what I ended up doing. I have a row of Here is a CodeSandbox with a working code const MyStyledButtonWithStyledApi = styled(IconButton)(({ theme, color }) => ({
flex: 1,
margin: 1,
borderRadius: 0,
[`& svg`]: {
color: blueGrey["400"]
},
[`&:hover, &.Mui-focusVisible`]: {
backgroundColor: alpha(theme.palette.primary.main, 0.1),
[`& svg`]: {
color: color === "error" ? theme.palette.error.main : blueGrey["700"]
}
}
})); The Here is a CodeSandbox using const MyStyledContainerWithStyledApi = styled("div")(({ theme }) => ({
display: "flex",
[`& .${iconButtonClasses.root}`]: {
flex: 1,
margin: 1,
borderRadius: 0,
[`& svg`]: {
color: blueGrey["400"]
},
[`&:hover, &.Mui-focusVisible`]: {
backgroundColor: alpha(theme.palette.primary.main, 0.1),
// set the standard hover color for all
[`& svg`]: {
color: blueGrey["700"]
},
// override the hover color just for error buttons
[`&.${iconButtonClasses.colorError} svg`]: {
color: theme.palette.error.main
}
}
}
})); |
Duplicates
Latest version
Current behavior 馃槸
The
color
prop on theIconButton
component allows any of thetheme.palatte
colors, but theiconButtonClasses
object only contains properties forcolorInherit
,colorPrimary
, andcolorSecondary
.If I want to target
IconButtons
withcolor="error"
usingstyled
orsx
then I have to use a hardcoded value of'.MuiIconButton-colorError'
(or look at the props directly).The
color
prop will work correctly for any color in the theme:material-ui/packages/mui-material/src/IconButton/IconButton.js
Lines 76 to 78 in dd4308d
It adds a targetable className
MuiIconButton-colorError
to the HTML:The documentation lists many accepted
color
values:Only 3 of these colors are present in
iconButtonClasses
:material-ui/packages/mui-material/src/IconButton/iconButtonClasses.ts
Lines 10 to 15 in dd4308d
Expected behavior 馃
I would expect that I could use
.${iconButtonClasses.colorError}
.I'm not sure if it's intentional that the "status" colors are missing or if it's an oversight. Other components such as
Icon
do have acolorError
class (but notcolorWarning
, etc.).Steps to reproduce 馃暪
Context 馃敠
I am trying to style a row of
IconButton
s and apply different hover colors depending on the component'scolor
prop.Your environment 馃寧
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: