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

[material-ui] Styles does not apply in same order #36211

Open
2 tasks done
cklaymen opened this issue Feb 15, 2023 · 1 comment
Open
2 tasks done

[material-ui] Styles does not apply in same order #36211

cklaymen opened this issue Feb 15, 2023 · 1 comment
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement

Comments

@cklaymen
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/nifty-night-37fimk?file=/src/App.tsx

Steps:

  1. Customize e.g. TextField background (filled variant) by adding & .MuiFilledInput-root { background: "white" }
  2. Check how it render and how hover/focus behave (hover and focus from Mui override our custom background white) (Screen 1)
  3. Now add original Mui TextField before the customized one and refresh page. Now check how the hover/active behave (hover and focus from Mui now DOES NOT override our custom background white - our custom style has higher priority than before) (Screen 2)

Screen 1:
image

Screen 2:
image

Current behavior 😯

Custom styled element does not always looks the same.

Expected behavior 🤔

Custom styled element should always looks the same.

Context 🔦

Want to the same styles always behave in the same way. Want styled element to be deterministic - the same style do the same thing every time.

Your environment 🌎

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
  
  Browser: Chrome 109
  
  "dependencies": {
    "@emotion/react": "11.10.5",
    "@emotion/styled": "11.10.5",
    "@mui/material": "5.11.8",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-scripts": "4.0.3"
  },
@cklaymen cklaymen added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 15, 2023
@mnajdova mnajdova self-assigned this Feb 16, 2023
@mnajdova
Copy link
Member

mnajdova commented Feb 16, 2023

The problem comes from the overrides having the same specificity as the style added for the hover selector. There is no guarantee which one will take precedence, as the styles are defined on different elements. In practice the override would need to contain the ":hover" styles too. For having a consistent styles, there are two options:

  1. define the styles for the hover styles too - this way they will always have a bigger specificity than the default background color override
  2. add the style override directly on the filled input component using the sx prop, for e.g.: https://codesandbox.io/s/unruffled-flower-k08yvq?file=/src/App.tsx
  3. We can add a variantMapping prop, where you can define custom filled input component, similarly to how we have in the Typography

In v6 we need to do something about this for sure.

@mnajdova mnajdova added support: question Community support but can be turned into an improvement component: text field This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 16, 2023
@mnajdova mnajdova added this to the v6 milestone Feb 16, 2023
@danilo-leal danilo-leal changed the title Styles does not apply in same order [material-ui] Styles does not apply in same order Dec 1, 2023
@danilo-leal danilo-leal added the package: material-ui Specific to @mui/material label Dec 1, 2023
@danilo-leal danilo-leal moved this to Backlog in Material UI Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement
Projects
Status: Backlog
Development

No branches or pull requests

5 participants