[SvgIcon] allow svg as a child#37231
Conversation
Netlify deploy previewBundle size report |
|
@mui/core @oliviertassinari Any feedback or thought on this? |
|
I like the benefits and solution, but I worry this might make the usage of
That's what I think might be confusing, and won't make sense unless the user checks |
Yes, that will be the trade-off with the DX. However, with clear documentation on how to use it, I don't think it will be confusing. |
|
You're right 😊 might we add that documentation in this PR as well? |
This comment was marked as spam.
This comment was marked as spam.
Good point! updated the docs to mention |
| height: '1em', | ||
| display: 'inline-block', | ||
| fill: 'currentColor', | ||
| fill: ownerState.hasSvgAsChild ? undefined : 'currentColor', |
There was a problem hiding this comment.
Let’s please add test for this
|
Aaah one thought, could this be considered a breaking change? We never supported svg before, right? If this is the case it should be fine |
@mnajdova I think this was a breaking change, but perhaps not if y'all never explicitly supported supplying Supplying We've since had to add Related: #40032 (comment) |

Motivation
I have come across this situation many many times where I copy svg from 3rd parties, e.g. https://lucide.dev/icons or https://heroicons.com/, then I have to remove
<svg>element all the time. I still needSvgIconbecause it makes the theming consistent likecolorandfontSizeprops.In another case using
createSvgIconin mui/mui-x#8940. I cannot set the default props that I want to use on thesvg:Solution
The
SvgIconshould work withsvgas a child. It will merge the props defined insvgwith theSvgIcon.Benefits
svgfrom anywhere and paste as a child to<SvgIcon>.svgelement when usingcreateSvgIconutil.