Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppBar] background-color and color styles not aligned between dark and light colorSchemes #43800

Open
croraf opened this issue Sep 17, 2024 · 7 comments
Assignees
Labels
component: app bar This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: question Community support but can be turned into an improvement

Comments

@croraf
Copy link
Contributor

croraf commented Sep 17, 2024

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/dark-theme-appbar-bug-forked-h6ymlh

Steps:

  1. Notice the styles on the AppBar in light mode
    image

  2. switch to dark mode using the button

  3. Notice the styles on the AppBar in dark mode
    image

Current behavior

In light scheme the background-color is set to var(--AppBar-background) while in dark scheme it is taken from dark.palette.background.paper (you can test this by changing this property in the theme in index.tsx).

Also in light scheme the color is set to var(--AppBar-color) while in dark scheme it is taken from dark.palette.text.primary (you can test this by changing this property in the theme in index.tsx)

Expected behavior

It is expected that both schemes behave the same.

Context

No response

Your environment

npx @mui/envinfo

System:
OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
Binaries:
Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
pnpm: Not Found
Browsers:
Chrome: 129.0.6668.58
npmPackages:
@emotion/react: ^11.13.3 => 11.13.3
@emotion/styled: ^11.13.0 => 11.13.0
@mui/base: 5.0.0-beta.58
@mui/core-downloads-tracker: 6.0.2
@mui/icons-material: ^6.0.2 => 6.0.2
@mui/lab: ^6.0.0-beta.9 => 6.0.0-beta.9
@mui/material: ^6.0.2 => 6.0.2
@mui/private-theming: 6.0.2
@mui/styled-engine: 6.0.2
@mui/styles: ^6.0.2 => 6.0.2
@mui/system: ^6.0.2 => 6.0.2
@mui/types: 7.2.16
@mui/utils: 5.16.6
@mui/x-charts: ^7.16.0 => 7.16.0
@mui/x-charts-vendor: 7.16.0
@mui/x-date-pickers: ^7.18.0 => 7.18.0
@mui/x-internals: 7.16.0
@mui/x-tree-view: ^7.16.0 => 7.16.0
@types/react: ^18.3.5 => 18.3.5
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
typescript: ^5.5.4 => 5.5.4

Search keywords: AppBar background dark light colorScheme

@croraf croraf added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 17, 2024
@zannager zannager added the component: app bar This is the name of the generic UI component, not the React module! label Sep 18, 2024
@jonesmac
Copy link

I think the problem with appbar might be more widespread. You can see in my screenshot, even though my theme is set to light mode, the app bar is still using styles as if my perferred color scheme is dark?

image

@jonesmac
Copy link

@croraf I think I solved it. It looks like this issue is caused by differences in extendTheme vs createTheme

If you use extendTheme, you will see the incorrect behavior where AppBar (and other paper backed components?) incorrectly use prefers-color-scheme: dark even though the theme provider is set to light mode.

Checkout the code sandbox here to see the issue. When in light mode, the app bar still has the grey background present in dark mode. However, if you switch from extendTheme to createTheme in lines 44-46 in the theme.tsx file, you will see the background of the appbar change correctly when switching themes.

@siriwatknp @zannager what is the correct behavior here? Should extendTheme behave differently than createTheme theme wrt paper-backed components?

@siriwatknp
Copy link
Member

@jonesmac please use createTheme in favor of extendTheme starting from v6.

I see that from your code, the styles is using @media (prefers-color-scheme). If you want the users to be able to toggle the modes from a control, you should add a colorSchemeSelector:

createTheme({
  cssVariables: {
+    colorSchemeSelector: 'class',
  }
})

@siriwatknp
Copy link
Member

@croraf Please provide a reproducible sandbox that we can take a look.

@siriwatknp siriwatknp added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 30, 2024
@croraf croraf changed the title [AppBar] background color not alligned between dark and light colorSchemes [AppBar] background-color and color styles not aligned between dark and light colorSchemes Sep 30, 2024
@croraf
Copy link
Contributor Author

croraf commented Sep 30, 2024

@siriwatknp updated

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Sep 30, 2024
@jonesmac
Copy link

@siriwatknp

@jonesmac please use createTheme in favor of extendTheme starting from v6.

I see that from your code, the styles is using @media (prefers-color-scheme). If you want the users to be able to toggle the modes from a control, you should add a colorSchemeSelector:

createTheme({
  cssVariables: {
+    colorSchemeSelector: 'class',
  }
})

@siriwatknp I've seen that note in the docs, however, it appears adding the colorSchemeSelector: 'class', property is NOT required to have the user switch the light/dark theme. See my codepen. Is this more of a suggestion for future compatability?

@siriwatknp
Copy link
Member

@siriwatknp siriwatknp added status: waiting for author Issue with insufficient information support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: app bar This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

4 participants