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.

[system] pseudo class overridden in slot

See original GitHub issue

v4: https://codesandbox.io/s/exciting-matsumoto-no6lr?file=/src/App.js OK

Capture d’écran 2021-06-23 à 12 53 54

v5: https://codesandbox.io/s/friendly-pasteur-e0q3t?file=/src/App.js KO

Capture d’écran 2021-06-23 à 12 53 59

This is a regression in v5.

Take a look at this Button theme example.

const theme = createTheme({
  components: {
    MuiButton: {
      styleOverrides: {
        contained: {
          '&.Mui-disabled': {
            opacity: 0.65
          }
        },
        containedPrimary: {
          '&.Mui-disabled': {
            color: "#fff",
            backgroundColor: palette.primary.main,
          }
        }
      }
    }
  }
})

<Button variant="contained" disabled /> // opacity 0.65 <Button variant="contained" color="primary" disabled /> // opacity is gone

This is because &.Mui-disabled in contained is overridden by containedPrimary from the implementation in Button.js.

// Button.js
...
overrideResolver: (props, styles) => {
  return {
    ...styles[styleProps.variant],
    ...styles[`${styleProps.variant}${capitalize(styleProps.color)}`],
  }
})
...

This makes customization harder because developer needs to know which key has higher priority.

The goal of this issue is to find a better DX to support theme customisation.

cc @mui-org/core

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
siriwatknpcommented, Jun 21, 2021

I wonder, do we need to support this behavior?

I strongly think that we should support. To me it is what I normally do in v4 and if we don’t support, migration to v5 could be frustrating because it is not only about Button or psuedo class, it is about the same key that get overridden in the object.

0reactions
oliviertassinaricommented, Jun 24, 2021

Regarding 1. the variant I would also advocate for fixing it 😁

Moved to #26944

Read more comments on GitHub >

github_iconTop Results From Across the Web

[system] pseudo class overridden in slot · Issue #26813 - GitHub
This is because &.Mui-disabled in contained is overridden by containedPrimary from the implementation in Button.js . // Button.js ...
Read more >
slotted() - CSS: Cascading Style Sheets - MDN Web Docs
The ::slotted() CSS pseudo-element represents any element that has been placed into a slot inside an HTML template (see Using templates and ...
Read more >
Override pseudo class elements bootstrap - Stack Overflow
In the above SCSS code I've tried to change the pseudo element content "/" to ">>" but the code is not working for...
Read more >
How to customize - Material UI - MUI
First, use your browser's dev tools to identify the class for the component slot you want to override. The styles injected into the...
Read more >
Importance of CSS Specificity and its best practices
The second slot is incremented by: Class selectors; pseudo-class selector; attribute selector. Whenever a rule meets the one of above mentioned ...
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