mui / mui/material-ui

CreateTheme Breaks overrides

Open
#37,043 5 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

customization: theme scope: all components support: question
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Steps to reproduce 🕹

Steps:

  1. Create an css file to override mui classes
    example:
.css-1hgf8cx-MuiInputBase-root-MuiOutlinedInput-root .MuiInputBase-input {
  color: var(--text);
}
  1. create a theme
  2. change typography fontfamily
Current behavior 😯

I currently Have a mui theme for my typography and am currently trying to add font family.

export const theme = createTheme({
  palette: {
    primary: blue,
    secondary: deepPurple,
  },
  typography: {
    allVariants: {
      color: "var(--text)",
      // breaks overrides
      fontFamily: "var(--fontFamilyTitle)",
    },
  },
});
Expected behavior 🤔

The intended functionality is to change the font family for my typography which it does...however for some reason adding a font family to my theme for typography breaks my override css.

image
image

vs without the font family in theme

image
image

Context 🔦

I currently have root css variables that are used when overriding mui classes for
certain things like input box border colors etc, I went to change the font family in create theme and my overrides no longer work. I went into the Inspector to look at the styles applied to the input that I override and all the sudden my override.css isnt even one of the styles that are applied at all.

Additionally I am following this stack overflow thread https://stackoverflow.com/questions/48319372/changing-font-family-of-all-mui-components.

For some reason if I make the font family like this.

      fontFamily: `"Roboto", "Helvetica", "Arial", sans-serif`,

I have no issues, I really dont understand what the problem is.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.