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.

Changing background colors for light and dark themes does not work

See original GitHub issue

Setting palette.types.light.background.default and palette.types.dark.background.default has no effect on background colors.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Setting these palette values should change background colors appropriately.

Current Behavior

The supplied background color values are ignored. Background color toggles only between #fafafa and #303030 - the default values.

Steps to Reproduce (for bugs)

Create custom theme:

const palette = {
    types: {
        dark: {
            background: {
                default: "#000000"
            }
        },
        light: {
            background: {
                default: "#ffffff"
            }
        }
    }
};

const theme = createMuiTheme({ palette });

Use this theme to set body background:

const styles = theme => ({
    '@global': {
        ...
        body: {
            background: theme.palette.background.default,
            ...
        }
    }
});

This will have no effect on the body background because the palette values are ignored. Background color can only toggle between #fafafa and #303030 based on the value of theme.palette.type.

I am currently using the following workaround, but this seems completely unnecessary:

const styles = theme => ({
    '@global': {
        ...
        body: {
            background: (theme.palette.type === 'light')
                ? theme.palette.types.light.background.default
                : theme.palette.types.dark.background.default,
            ...
        }
    }
});

Context

The reason I want to change the default background colors is to be able to embed the react app in an iframe. The hosting page has a white background and the default of #fafafa is clashing with it.

Your Environment

Tech Version
Material-UI 1.0.0-beta.28
React 16.x
browser N/A
etc

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
mbrookescommented, Jan 24, 2018

@nareshbhatia Could you follow the Material-UI docs pattern?

function getTheme(theme) {
  return createMuiTheme({
    palette: {
      type: theme.paletteType,
      background: {
        default: theme.paletteType === 'light' ? #000' : '#fff',
      },
    },
  });
}

const theme = getTheme({
  paletteType: 'light',
});
0reactions
MutableLosscommented, Jan 21, 2019

@oliviertassinari Thanks for the heads up!

Are there any examples of this usage somewhere? I didn’t see anything with the muithemeprovider API docs. I will definitely check the source later tonight once I have some time, since that particular example I ran across gave me the wrong impression, and left me with a theme that was being unused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing background colors for light and dark themes does ...
This will have no effect on the body background because the palette values are ignored. Background color can only toggle between #fafafa and...
Read more >
SCSS darkmode switch background color not working
I am looking more for a default light-theme and if the user wants he/she can switch the theme-mode with a switch (toggler) button....
Read more >
Change to dark or color mode on your Android device
If light theme is on but an app is dark, it could be: Dark theme is on for the app, but not for...
Read more >
559321 – [Dark Theme] Custom editor background color not ...
In the first, you can see that setting the background color to blue and then clicking "Apply" updates the entire editor as expected....
Read more >
Support Dark and Light themes in Win32 apps - Microsoft Learn
Learn how to detect system theme changes for dark or light mode. ... Theme colors can often be light but not pure white,...
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