question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot override MUI icon default styling when using 5.0 beta.

See original GitHub issue

I cannot increase the font-size of an MUI icon.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

MUI styling is overriding custom styling

Expected Behavior 🤔

Custom styling should override default MUI styling

Steps to Reproduce 🕹

This sandbox shows a icon with custom styling that overrides the default styling (which is correct):

https://codesandbox.io/s/intelligent-dewdney-1t832?file=/src/Demo.tsx image

    "@emotion/react": "11.4.1",
    "@emotion/styled": "11.3.0",
    "@material-ui/core": "4.12.3",
    "@material-ui/icons": "4.11.2",
    "@material-ui/styles": "4.11.4",
    "react": "latest",
    "react-dom": "latest",
    "react-scripts": "latest"

But when certain packages are upgraded the default styling starts to override the custom styling:

https://codesandbox.io/s/heuristic-scott-5z5ng?file=/package.json image

    "@emotion/react": "11.4.1",
    "@emotion/styled": "11.3.0",
    "@material-ui/core": "5.0.0-beta.5",
    "@material-ui/icons": "5.0.0-beta.5",
    "@material-ui/styles": "5.0.0-beta.5",
    "react": "latest",
    "react-dom": "latest",
    "react-scripts": "latest"

Updating all material ui packages doesn’t help either:

https://codesandbox.io/s/hopeful-lalande-x27e0?file=/src/Demo.tsx image

    "@mui/icons-material": "5.0.0-rc.1",
    "@mui/material": "5.0.0-rc.1",
    "@mui/styles": "5.0.0-rc.1",

Only this method seems to work: <AccountCircle style={{ fontSize: 40 }}/>

Context 🔦

Trying to increase a MUI icon fontsize so I can use it as a button.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mnajdovacommented, Sep 16, 2021

Sorry I didn’t notice that the last example was using style.

Here is a working sandbox: https://codesandbox.io/s/laughing-alex-nyszr?file=/src/index.tsx

Note that you need to wrap your app with StyledEngineProvider with inject first so that the emotion styles would be injected before the JSS ones. This is documented in the Styled library interoperability guide - https://mui.com/guides/interoperability/

There are four ways of how you can do this:

  • classes, className, sx prop or style

I hope this helps

1reaction
mnajdovacommented, Sep 22, 2021

Sorry for the late response. If you use v5 with the recommended v5 styling mechanism you don’t need StyledEngineProvider, StyledProvider nor ThemeProvider if you are using the default theme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot override default Material UI Icon styling - Stack Overflow
Cannot override default Material UI Icon styling · It works using version 4.12. · Just recreated the issue in a codesandbox codesandbox.io/s/ ...
Read more >
Can't override IconButton styles in theme without affecting ...
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >
Struggling to override some of the default styling in Material UI ...
I'm currently trying to change the padding on an MUI Button component but it doesn't seem to be working as the MUI styling...
Read more >
Migrating to v5: getting started - Material UI - MUI
One of the biggest changes in v5 is the replacement of JSS for Emotion as a default styling solution. Note that you may...
Read more >
mui-datatables - npm
Start using mui-datatables in your project by running `npm i ... doesn't already use them, you need to install mui v5 and it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found