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

[theme] How to override the styles of the disabled property? #44271

Closed
VictorTrumpel opened this issue Oct 30, 2024 · 3 comments
Closed

[theme] How to override the styles of the disabled property? #44271

VictorTrumpel opened this issue Oct 30, 2024 · 3 comments
Assignees
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system support: question Community support but can be turned into an improvement

Comments

@VictorTrumpel
Copy link

VictorTrumpel commented Oct 30, 2024

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/objective-hamilton-8cwwr2?file=%2Fsrc%2FApp.js%3A6%2C1

Steps:

  1. add theme

Current behavior

Background color isn't red

Expected behavior

Background color is red

Context

Themin

Your environment

all browsers

Search keywords: disabled property override theme

@VictorTrumpel VictorTrumpel added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 30, 2024
@zannager zannager added package: system Specific to @mui/system customization: theme Centered around the theming features labels Oct 30, 2024
@ZeeshanTamboli
Copy link
Member

Targeting using disabled class works. See https://codesandbox.io/p/sandbox/peaceful-dhawan-8pyj6r. But I think disabled as a prop should also be allowed in variants, or we should pick one method (prop or class) and document it. cc @siriwatknp

@ZeeshanTamboli ZeeshanTamboli changed the title It is impossible to override the styles of the disabled property [theme] How to override the styles of the disabled property Nov 2, 2024
@ZeeshanTamboli ZeeshanTamboli changed the title [theme] How to override the styles of the disabled property [theme] How to override the styles of the disabled property? Nov 2, 2024
@siriwatknp
Copy link
Member

image

@ZeeshanTamboli Actually, the custom style is applied to the Button but the default disabled styles has higher specificity.

This is expected for styling, disabled should have higher specificity. The correct approach is to either use a class or :disabled CSS selector:

const theme = createTheme({
  components: {
    MuiButton: {
      styleOverrides: {
        root: {
          variants: [
            {
              props: { variant: "contained" },
              style: {
                '&:disabled': {
                  background: 'black',
                }
              },
            },
          ],
        },
      },
    },
  },
});

@siriwatknp siriwatknp added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 12, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@VictorTrumpel How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

4 participants