-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[SvgIcon] Fix passing an ownerState to SvgIcon changes the font size #34429
[SvgIcon] Fix passing an ownerState to SvgIcon changes the font size #34429
Conversation
/** Styles applied to the root element if `fontSize="medium"`. */ | ||
fontSizeMedium: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the issue, but found this class was missing in types.
@@ -47,7 +47,7 @@ const SvgIconRoot = styled('svg', { | |||
inherit: 'inherit', | |||
small: theme.typography?.pxToRem?.(20) || '1.25rem', | |||
medium: theme.typography?.pxToRem?.(24) || '1.5rem', | |||
large: theme.typography?.pxToRem?.(35) || '2.1875', | |||
large: theme.typography?.pxToRem?.(35) || '2.1875rem', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rem
unit was missing, not related to the issue.
ownerState
as a prop shouldn't affect internal ownerState
this.skip(); | ||
} | ||
|
||
const { container } = render(<SvgIcon ownerState={{ fontSize: 'sm' }}>{path}</SvgIcon>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a real use case to test this one? I ask this because I plan to change the test file to .tsx
and I am pretty sure that the SvgIcon
does not support ownerState
prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the icon slot in MUI X Pickers does pass ownerState
for CSS customization based on ownerState. Also, you can see it in the before and after CodeSandboxes in the description, so we need it.
You can use // @ts-expect-error
comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks @ZeeshanTamboli
Fixes #34056
When a custom SVG icon is provided in components slot and the slot's
componentsProps
is defined with theuseSlotProps
hook, it should not override theownerState
of the internal SvgIcon.The
styled
API does prevent forwardingownerState
of the hook, but if customizing components by other methods, the ownerState passed to the hook overrides the internal one of the SVG Icon.Even if custom icon component is not provided, the
ownerState
passed to the hook is causing changes in the svgicon default styling.Before: https://codesandbox.io/s/data-grid-community-forked-5hnr7p?file=/src/App.tsx
After: https://codesandbox.io/s/data-grid-community-forked-p1d7rr