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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typography] margin property is attached to root style by default #30360

Closed
2 tasks done
nikhilgupta46 opened this issue Dec 22, 2021 · 4 comments
Closed
2 tasks done
Assignees
Labels
component: Typography The React component. support: question Community support but can be turned into an improvement v5.x migration

Comments

@nikhilgupta46
Copy link

nikhilgupta46 commented Dec 22, 2021

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

The problem is that in latest V5 Typography there is by default { margin : 0 } being extended in classes and therefore the margin is getting attached to the root styles which is then being override only by applying !important to the margin from the classes.
During the initial createTheme I am not able to remove the margin or set it to null so that it doesn't get attached to the default root styles .
Screenshot 2021-12-22 at 2 46 40 PM

Expected behavior 馃

Need to confiigure such that from the properties exposed through createTheme ( e.g. styleOverrides ) that margin property doesn't get attached to root styles and only properties that I specify remains intact to it
Screenshot 2021-12-22 at 2 47 16 PM

Steps to reproduce 馃暪

Steps:

Context 馃敠

setting margin property through classes to the typography component doesn't override it until important is appended to margin value since attachment of margin : 0 a root by default need to overwrite margin from classes without specifying important

Your environment 馃寧

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@nikhilgupta46 nikhilgupta46 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 22, 2021
@hbjORbj hbjORbj changed the title MaterialUi Typography : margin property by default getting attached to root typography styles no way to remove it [Typography] margin property is attached to root style by default Dec 22, 2021
@hbjORbj hbjORbj added the component: Typography The React component. label Dec 22, 2021
@mnajdova
Copy link
Member

The margin: 0 was there in v4 too https://github.com/mui-org/material-ui/blob/v4.x/packages/material-ui/src/Typography/Typography.js#L10 it is not something new to v5. In your global styles, you can use:

& .MuiTypography-root {
  margin: '10px', // or whatever value you need
}

This way you don't need to use !important

@mnajdova mnajdova removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 22, 2021
@nikhilgupta46
Copy link
Author

@mnajdova the point is that I have override the typography h1 variant with these properties
( fontSize,
fontWeight,
lineHeight
letterSpacing,
fontFamily
color )
that were specified in globalStyles but margin property is by default attached to it's root level properties
so when using typography with variant= "h1" and passing className which has marginRight:10px doesn't work without important ( I want to get rid of margin prop in root to override it through classes without using important )
Screenshot 2021-12-22 at 5 06 50 PM

Screenshot 2021-12-22 at 4 59 27 PM

@nikhilgupta46
Copy link
Author

@mnajdova I could comment margin :0 in node_modules / typography but that is a patchy fix which i don't want so wanted to solve through any props exposed
Screenshot 2021-12-22 at 5 50 07 PM

@mnajdova
Copy link
Member

Are you using @mui/styles (makeStyles) with the v5 of @mui/material? If this is the case you are likely missing StyledEngineProvider with injectFirst. See https://mui.com/guides/interoperability/#css-injection-order

If this is not the case please create a CodeSandbox illustrating the issue.

@mnajdova mnajdova added the status: waiting for author Issue with insufficient information label Dec 23, 2021
@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement v5.x migration and removed status: waiting for author Issue with insufficient information labels Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. support: question Community support but can be turned into an improvement v5.x migration
Projects
None yet
Development

No branches or pull requests

4 participants