question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MuiCssBaseline component styleOverrides in custom theme is not working

See original GitHub issue

What you were expecting: To be able to change the body background image using MuiCssBaseline component styleOverrides.

What happened instead: body tag is not styled at all by the theme

Steps to reproduce:

Go to: https://stackblitz.com/edit/github-br7omu?file=src%2Findex.tsx,src%2FmyTheme.ts,src%2Fposts%2FPostList.tsx

You should see a fat blue dashed border at the body of the document, but there isn’t. In contrast, RaDatagrid overrides are working.

import { defaultTheme } from 'react-admin';
import indigo from '@mui/material/colors/indigo';
import pink from '@mui/material/colors/pink';
import red from '@mui/material/colors/red';

export const myTheme = {
  ...defaultTheme,
  palette: {
    primary: indigo,
    secondary: pink,
    error: red,
    contrastThreshold: 3,
    tonalOffset: 0.2,
  },
  components: {
    ...defaultTheme.components,
    RaDatagrid: {
      styleOverrides: {
        root: {
          backgroundColor: 'green',
        },
      },
    },
    MuiCssBaseline: {
      styleOverrides: {
        body: {
          border: '20px dashed blue',
        },
      },
    },
  },
};

Other information:

Environment

  • React-admin version: 4.5
  • Last version that did not exhibit the issue (if applicable): n/a
  • React version: 18
  • Browser: Chrome

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
christiaanwesterbeekcommented, Nov 9, 2022

Thanks man! I was trying al sorts of combinations including MuiScopedCssBaseline, but didn’t try ScopedCssBaseline

0reactions
WiXSLcommented, Nov 9, 2022

You are right! Sorry I missed that

Read more comments on GitHub >

github_iconTop Results From Across the Web

[CssBaseline] Gives typescript error when styleOverrides ...
Duplicates I have searched the existing issues Latest version I have ... components: { MuiCssBaseline: { styleOverrides: (theme: Theme) ...
Read more >
Mui v5 styleOverrides not working with themes - Stack Overflow
The issue is that Select doesn't define any styles of its own at ... const theme = createTheme({ components: { MuiSelect: { styleOverrides: ......
Read more >
CSS Baseline - Material UI - MUI
The CssBaseline component helps to kickstart an elegant, consistent, ... const theme = createTheme({ components: { MuiCssBaseline: { styleOverrides: ...
Read more >
Global Styling with Material-UI Theme Overrides and Props
Learn how to use global CSS overrides and default props in a theme to customize all instances of a Material-UI component in a...
Read more >
@mui/material CssBaseline TypeScript Examples
StrictMode> <CssBaseline /> <ThemeProvider theme={appTheme}> <BrowserRouter> ... const theme = createCMSDefaultTheme({ mode }); let component; if (loading) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found