[system] Counter intuitive behavior when overriding media queries
See original GitHub issue- 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 😯
I’m unable to override certain styles on components. In this example, I’m trying to override the minHeight
property on a Toolbar
component.
I was eventually able to override that property by adding !important
to my style but according to the docs, that doesn’t seem like it should be necessary. I would expect any provided styles to be applied last and thus override the default styles.
Expected Behavior 🤔
Based on the documentation, I would expect to be able to…
- use
sx
to override this directly on the component (<Toolbar sx={{ minHeight: '0px' }}>...
) - OR create a variant in the
theme
to be able to enable that specific style override - OR use
styled
to create a one-off component variant that has those styles applied to it
Steps to Reproduce 🕹
CodeSandbox Example using sx
(preferred method), styled
, and theme
Context 🔦
I was used to overriding styles via withStyles
or the classes
prop in v4 but it’s unclear to me how to override styles without using !important
in my styles.
Your Environment 🌎
`npx @mui/envinfo`
System:
OS: macOS 11.6
Binaries:
Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
npm: 7.24.2 - ~/.nvm/versions/node/v14.16.1/bin/npm
Browsers:
Chrome: 94.0.4606.71 (browser being used)
Edge: 94.0.992.38
Firefox: 92.0
Safari: 15.0
npmPackages:
@emotion/react: ^11.4.1 => 11.4.1
@emotion/styled: ^11.3.0 => 11.3.0
@mui/core: 5.0.0-alpha.50
@mui/icons-material: ^5.0.3 => 5.0.3
@mui/material: ^5.0.3 => 5.0.3
@mui/private-theming: 5.0.1
@mui/styled-engine: 5.0.1
@mui/styles: ^5.0.1 => 5.0.1
@mui/system: 5.0.3
@mui/types: 7.0.0
@mui/utils: 5.0.1
@types/react: 17.0.14
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:19 (15 by maintainers)
Top Results From Across the Web
media queries - one rule overrides another? - Stack Overflow
Seems counter-intuitive that media queries should not take priority just by the fact that they are more narrowly scoped. Apparently, even a non- ......
Read more >Counterintuitive Behavior - an overview | ScienceDirect Topics
Social dynamics is fraught with counterintuitive behavior. It stands on a level of complexity beyond the reach of analytical approach.
Read more >media styles are applied in the wrong order · Issue #1860
Current behavior: When using the '@media...' selector, the styles are always applied after non-media styles, regardless of their order in ...
Read more >Approaches to Media Queries in Sass - CSS-Tricks
The mixin comes with a set of default breakpoints, which you can override anywhere in the code by re-declaring the variable $breakpoints ....
Read more >Overriding built-in Caspio media queries with !important flag
Is there any way for me to overwrite the code from within Caspio's system? Quote ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ye, I know 😛 just showcasing how you can end up with this “unwanted” situation with vanilla CSS too (so it’s not specific to Emotion)
I think the diagnosis here is correct - when you compose styles are “folded” into a single class name and the rest is just CSS behavior.
While this issue is slightly about a different problem I think it might actually shed some additional light on the issue here: https://github.com/emotion-js/emotion/issues/1860 .