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

custom css variable don't override all styles #44252

Closed
violabg opened this issue Oct 29, 2024 · 4 comments
Closed

custom css variable don't override all styles #44252

violabg opened this issue Oct 29, 2024 · 4 comments
Labels
customization: theme Centered around the theming features support: Stack Overflow Please ask the community on Stack Overflow

Comments

@violabg
Copy link

violabg commented Oct 29, 2024

Steps to reproduce

Link to live example: (required)
https://stackblitz.com/edit/github-j7eeqn?file=src%2Ftheme.tsx

Steps:

  1. run the project

Current behavior

I overwrote the
--mui-palette-primary-main with custom color

but icons and Switch components still show the default

Expected behavior

the --mui-palette-primary-main color should be applied to all components

also in order to override the style I had to use !important is this correct or I'm doing something wrong

Context

No response

Your environment

No response

Search keywords: css variables

@violabg violabg added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 29, 2024
@mj12albert mj12albert added customization: theme Centered around the theming features and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 29, 2024
@mj12albert
Copy link
Member

is this correct or I'm doing something wrong

@violabg The recommended way is to configure everything in createTheme 😬

const theme = createTheme({
  cssVariables: true,
  palette: {
    primary: {
      main: '#ffc627',
    },
  },
});

See the docs here: https://mui.com/material-ui/customization/palette/#customization

@mj12albert mj12albert added the support: Stack Overflow Please ask the community on Stack Overflow label Oct 29, 2024
Copy link

👋 Thanks for using this project!

We use GitHub issues exclusively as a bug and feature requests tracker, however, this issue appears to be a support request.

For support with Material UI please check out https://mui.com/material-ui/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@violabg
Copy link
Author

violabg commented Oct 29, 2024

I'm referring to https://mui.com/material-ui/customization/css-theme-variables/usage/#getting-started

that explicitly says

import { ThemeProvider, createTheme } from '@mui/material/styles';

const theme = createTheme({ cssVariables: true });

function App() {
  return <ThemeProvider theme={theme}>{/* ...your app */}</ThemeProvider>;
}
:root {
  --mui-palette-primary-main: #1976d2;
  --mui-palette-primary-light: #42a5f5;
  --mui-palette-primary-dark: #1565c0;
  --mui-palette-primary-contrastText: #fff;
  /* ...other variables */
}

so I still think there is a bug with the disabled Switch component.

regarding the icons problem I realised that I need to use theme.var in order to access the variable value

@mj12albert
Copy link
Member

That CSS snippet is an example of the CSS generated by configuring your colors in createTheme, you're not meant to manually import a css file like that ~

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 support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

2 participants