0

I have recently started using Material ui (v5) and I am facing some issues with theme customization. I want to change the font-family for all the components through the ThemeProvider and creating a new theme. I am able to see the theme in the react inspector with the correct values but those values don't get applied to the components (specifically fontFamily but nothing works really).

This is what my ThemeProvider looks like:

import React from "react";
import {
  createTheme,
  ThemeProvider as MUIThemeProvider,
} from "@mui/material/styles";

const theme = createTheme({
  typography: {
    fontFamily: "serif",
  },
});

type ThemeProviderProps = {
  children: React.ReactNode;
};

const ThemeProvider = ({ children }: ThemeProviderProps) => (
  <MUIThemeProvider theme={theme}>{children}</MUIThemeProvider>
);

export default ThemeProvider;

The ThemeProvider then wraps every story (using storybook):

  <div
    style={{
      height: "100%",
      width: "100%",
    }}
  >
    <ThemeProvider>
      <Story {...context} />
    </ThemeProvider>
  </div>
);

export const decorators = [withThemeProvider];```

I am able to see the theme I created if I use the useTheme hook or in the ThemeProvider in the components inspector (please ignore the different fontFamily in the screenshot below):

enter image description here

enter image description here

When I look at the actual component I see that it is still getting the default styles:

enter image description here

I am sure I am doing something stupid somewhere?

Ninjabin
  • 97
  • 5
  • https://stackoverflow.com/questions/48319372/changing-font-family-of-all-mui-components – Madhuri Dec 20 '21 at 17:09
  • https://stackoverflow.com/questions/70253373/mui-v5-storybook-theme-and-font-family-do-not-work-in-storybook/70254078#70254078 – Sam A. Dec 20 '21 at 21:01

0 Answers0