Skip to content
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

Merged

Conversation

ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli commented Sep 22, 2022

Fixes #34056

When a custom SVG icon is provided in components slot and the slot's componentsProps is defined with the useSlotProps hook, it should not override the ownerState of the internal SvgIcon.

The styled API does prevent forwarding ownerState 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

@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work component: SvgIcon The React component. package: material-ui Specific to @mui/material package: joy-ui Specific to @mui/joy labels Sep 22, 2022
@mui-bot
Copy link

mui-bot commented Sep 22, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 5e121bb

Comment on lines +20 to +21
/** Styles applied to the root element if `fontSize="medium"`. */
fontSizeMedium: string;
Copy link
Member Author

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',
Copy link
Member Author

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.

@ZeeshanTamboli ZeeshanTamboli marked this pull request as ready for review September 22, 2022 11:04
@ZeeshanTamboli ZeeshanTamboli changed the title [SvgIcon] Fix passing external ownerState as a prop shouldn't affect internal ownerState [SvgIcon] Fix passing an ownerState to SvgIcon changes the font size Sep 22, 2022
this.skip();
}

const { container } = render(<SvgIcon ownerState={{ fontSize: 'sm' }}>{path}</SvgIcon>);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @ZeeshanTamboli

@siriwatknp siriwatknp merged commit 84a7619 into mui:master Sep 26, 2022
@ZeeshanTamboli ZeeshanTamboli deleted the issue/34056-ownerState-to-svgicon branch September 26, 2022 05:28
alexfauquette pushed a commit to alexfauquette/material-ui that referenced this pull request Oct 14, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: SvgIcon The React component. package: joy-ui Specific to @mui/joy package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SvgIcon] Passing an ownerState to SvgIcon changes the font size
3 participants