Custom font size in `ThemedLayoutV2`

Where is the font size configured for the ThemedLayoutV2 component using the Material UI integration? The component is ignoring the font size declared in the typography object used in the createTheme object passed as a prop to ThemeProvider.
2 Replies
kapa.ai
kapa.ai2w ago
Hi @Nitai. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources, I can see that you're having an issue with customizing the font size in ThemedLayoutV2 when using Material UI integration with refine. When customizing typography in Material UI with refine, there appears to be a specific way to properly override the font family (and by extension, font sizes). According to the documentation and a reported issue, you need to recreate the theme using createTheme and properly structure your typography options. The issue you're experiencing might be similar to what was reported in this GitHub issue, where simply overriding typography properties wasn't working correctly. Here's how you should properly configure font sizes (and other typography properties) for ThemedLayoutV2:
import { RefineThemes } from "@refinedev/mui";
import { TypographyVariantsOptions, createTheme } from "@mui/material/styles";

// Define your typography options
const typographyOptions: TypographyVariantsOptions = {
// Your font size customizations go here
fontSize: 16, // Base font size
h1: {
fontSize: '2.5rem',
},
h2: {
fontSize: '2rem',
},
// other typography variants...
};

// Create a new theme that extends RefineThemes.Blue (or any other theme)
const customTheme = createTheme({
...RefineThemes.Blue,
typography: {
...typographyOptions,
},
});
import { RefineThemes } from "@refinedev/mui";
import { TypographyVariantsOptions, createTheme } from "@mui/material/styles";

// Define your typography options
const typographyOptions: TypographyVariantsOptions = {
// Your font size customizations go here
fontSize: 16, // Base font size
h1: {
fontSize: '2.5rem',
},
h2: {
fontSize: '2rem',
},
// other typography variants...
};

// Create a new theme that extends RefineThemes.Blue (or any other theme)
const customTheme = createTheme({
...RefineThemes.Blue,
typography: {
...typographyOptions,
},
});
Then pass this custom theme to the ThemeProvider:
<ThemeProvider theme={customTheme}>
{/* Your app with ThemedLayoutV2 */}
</ThemeProvider>
<ThemeProvider theme={customTheme}>
{/* Your app with ThemedLayoutV2 */}
</ThemeProvider>
If this approach doesn't work, you might need to use the "swizzle" feature to customize the ThemedLayoutV2 component directly. As mentioned in the Customizing with swizzle section, you can eject the component's source code to your project and modify it directly. The swizzle command will create a copy of the component in your project's src directory, allowing you to customize it according to your specific needs, including font sizes that might be hardcoded in the component. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@1091820430047838349> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?