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

Box styles don't have highest priority #24277

Closed
2 tasks done
jbojcic1 opened this issue Jan 5, 2021 · 4 comments
Closed
2 tasks done

Box styles don't have highest priority #24277

jbojcic1 opened this issue Jan 5, 2021 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@jbojcic1
Copy link

jbojcic1 commented Jan 5, 2021

When you wrap syled component with Box with clone set to true, the Box styles should override the styles of the styled component.

  • 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 😯

Box styles are overridden by the inner styled component styles.

Expected Behavior 🤔

Docs state:
⚠️ The CSS specificity relies on the import order. If you want the guarantee that the wrapped component's style will be overridden, you need to import the Box last.
So my understanding is that Box styles should override the styles of the styled component if Box is imported last.

Steps to Reproduce 🕹

https://codesandbox.io/s/charming-feather-yji6s?file=/src/App.js

Notice how width of inner styled div wins over Box width even though I imported box last.

@jbojcic1 jbojcic1 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 5, 2021
@oliviertassinari
Copy link
Member

Duplicate of #18496

@oliviertassinari oliviertassinari marked this as a duplicate of #18496 Jan 5, 2021
@oliviertassinari oliviertassinari removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 5, 2021
@github-actions github-actions bot added the duplicate This issue or pull request already exists label Jan 5, 2021
@oliviertassinari
Copy link
Member

  1. We are removing this prop in v5.
  2. You can configure the CSS injection order, we document it in the docs.

@jbojcic1
Copy link
Author

jbojcic1 commented Jan 5, 2021

@oliviertassinari regarding #2 are you referring to this https://material-ui.com/styles/advanced/#css-injection-order?

I've read that but I don't understand how that affects Box component styles. I understand I can tell it where to inject all material styles in the head but what I don't understand is how to tell it to always put only Box styles to the bottom.

And import order doesn't seem to work for me either as importing the Box last doesn't help.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 5, 2021

@jbojcic1 In your case, the simplest is to upgrade to v5: you get the sx prop for free (unless disabled) when using styled (currently exposed as experimentalStyled): https://codesandbox.io/s/sad-euler-g8b2m?file=/src/App.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants