-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Closed
Labels
good first issueGreat for first contributions. Enable to learn the contribution process.Great for first contributions. Enable to learn the contribution process.scope: icon buttonChanges related to the icon button.Changes related to the icon button.type: bugIt doesn't behave as expected.It doesn't behave as expected.
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
When I augment IconButton with new colors that don't exist in the palette:
declare module "@mui/material/IconButton" {
interface IconButtonPropsColorOverrides {
textPrimary: true;
textSecondary: true;
}
}and then try to use these colors:
<IconButton color="textPrimary">
<CloseIcon />
</IconButton>My app crashes with:
TypeError: Cannot read properties of undefined (reading 'main')
at the following location:
| color: (theme.vars || theme).palette[ownerState.color].main, |
Expected behavior 🤔
IconButton doesn't throw TypeError when using custom color. Instead it handles it safely, like SvgIcon:
| (theme.vars || theme).palette?.[ownerState.color]?.main ?? |
Steps to reproduce 🕹
No response
Context 🔦
We intend for color="textPrimary" (or color="text.primary", both are fine) to use the text.primary palette color.
Workaround: pass the color to the icon component instead and augment SvgIconPropsColorOverrides typings:
<IconButton>
<CloseIcon color="textPrimary" />
</IconButton>Your environment 🌎
No response
Metadata
Metadata
Assignees
Labels
good first issueGreat for first contributions. Enable to learn the contribution process.Great for first contributions. Enable to learn the contribution process.scope: icon buttonChanges related to the icon button.Changes related to the icon button.type: bugIt doesn't behave as expected.It doesn't behave as expected.