Skip to content

[AppBar] Color does not apply in dark mode #28962

Closed

Description

@Mossop
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When using createTheme and changing the palette to dark mode the rest of the provided palette appears to be ignored.

Expected Behavior 🤔

I should be able to select dark mode and customize a couple of the palette's colours.

Steps to Reproduce 🕹

See the example where I use createTheme, select dark mode and set the primary colour to red. The display shows an AppBar which I want to use my intended primary colour (red).

https://codesandbox.io/s/material-ui-5-0-3-dark-theme-forked-7pfe3?file=/src/App.js:190-208

As you can see the app bar actually has a grey background. If I remove the mode: "dark" from the code then the app bar does go red but of course the rest of the palette becomes light mode.

Context 🔦

I want a slightly altered version of the dark mode palette. I shouldn't have to manually set every single colour just to change a few.

Your Environment 🌎

`npx @mui/envinfo` ``` System: OS: macOS 11.6 CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz Memory: 16.28 GB / 64.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 16.10.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.24.0 - /usr/local/bin/npm Watchman: 2021.09.13.00 - /usr/local/bin/watchman Managers: Cargo: 1.54.0 - ~/.cargo/bin/cargo Homebrew: 3.2.13 - /usr/local/bin/brew pip3: 21.1.3 - ~/dotfiles/external/pyenv/shims/pip3 RubyGems: 3.0.3 - /usr/bin/gem Utilities: Make: 3.81 - /usr/bin/make GCC: 4.2.1 - /usr/bin/gcc Git: 2.33.0 - /usr/local/bin/git Clang: 13.0.0 - /usr/bin/clang Mercurial: 5.8.1 - /Users/dave/dotfiles/external/pyenv/shims/hg FFmpeg: 4.4 - /usr/local/bin/ffmpeg Servers: Apache: 2.4.48 - /usr/sbin/apachectl Virtualization: Docker: 20.10.8 - /usr/local/bin/docker SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 IDEs: Nano: 2.0.6 - /usr/bin/nano VSCode: 1.61.0 - /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code Vim: 8.2 - /usr/bin/vim Xcode: 13.0/13A233 - /usr/bin/xcodebuild Languages: Bash: 5.1.8 - /usr/local/bin/bash Perl: 5.30.2 - /usr/bin/perl PHP: 7.3.29 - /usr/bin/php Python: 3.9.4 - /Users/dave/dotfiles/external/pyenv/shims/python Python3: 3.9.4 - /Users/dave/dotfiles/external/pyenv/shims/python3 Ruby: 2.6.3 - /usr/bin/ruby Rust: 1.54.0 - /Users/dave/.cargo/bin/rustc Databases: SQLite: 3.32.3 - /usr/bin/sqlite3 Browsers: Chrome: 94.0.4606.71 Firefox: 86.0 Firefox Developer Edition: 82.0 Firefox Nightly: 95.0a1 Safari: 15.0 ```

Activity

  1. added
    status: waiting for maintainer
    on Oct 10, 2021
  2. abhinav-22-tech commented on Oct 10, 2021

    @abhinav-22-tech
    Contributor

    If we use enableColorOnDark in <AppBar> it worked.
    Please check out the given below link:

    https://codesandbox.io/s/material-ui-5-0-3-dark-theme-forked-p3bji?file=/src/App.js

  3. Mossop commented on Oct 10, 2021

    @Mossop
    Author

    Ok, is there some way to not need to add that attribute to every element I want coloured correctly? This worked ok in v4.

  4. siriwatknp commented on Oct 11, 2021

    @siriwatknp
    Member

    Ok, is there some way to not need to add that attribute to every element I want coloured correctly? This worked ok in v4.

    Yes, you can specify the default props in createTheme like this, it will apply to all AppBar under ThemeProvider:

    const theme = createTheme({
      palette: {
        mode: "dark",
        primary: {
          main: "#FF0000"
        }
      },
      components: {
        MuiAppBar: {
          defaultProps: {
            enableColorOnDark: true
          }
        }
      }
    });

    https://codesandbox.io/s/material-ui-5-0-3-dark-theme-forked-o6glf?file=/src/App.js

  5. changed the title [-]Cannot customize palette in dark mode[/-] [+][AppBar] Color does not apply in dark mode[/+] on Oct 11, 2021
  6. added
    scope: app bar
    and removed
    status: waiting for maintainer
    on Oct 11, 2021
  7. siriwatknp commented on Oct 11, 2021

    @siriwatknp
    Member

    I think this can be improved by adding one example in the docs. I marked this as "Good First Issue" in case anyone wants to work on it.

  8. added
    docs
    good first issue
    on Oct 11, 2021
  9. oliviertassinari commented on Oct 11, 2021

    @oliviertassinari
    Member

    There is a section in the documentation about this problem: https://mui.com/components/app-bar/#enable-color-on-dark. Is the proposed solution to add an illustration demo to it?

  10. abhinav-22-tech commented on Oct 11, 2021

    @abhinav-22-tech
    Contributor

    @siriwatknp Can you clarify more in detail?

    Do I have to update the docs from -

    <ThemeProvider
      theme={createTheme({
        components: {
          MuiAppBar: {
            defaultProps: {
              enableColorOnDark: true,
            },
          },
        },
      })}
    >
      <AppBar />
    </ThemeProvider>
    

    to this -

    const theme = createTheme({
      palette: {
        mode: "dark",
        primary: {
          main: "#FF0000"
        }
      },
      components: {
        MuiAppBar: {
          defaultProps: {
            enableColorOnDark: true
          }
        }
      }
    });
    
  11. siriwatknp commented on Oct 11, 2021

    @siriwatknp
    Member

    @oliviertassinari Yes, I think it should give more clarity to developers.

  12. siriwatknp commented on Oct 11, 2021

    @siriwatknp
    Member

    I think this can be improved by adding one example in the docs. I marked this as "Good First Issue" in case anyone wants to work on it.

    @siriwatknp I would like to work on it, could you please clarify what do you have in mind?

    As @oliviertassinari said, there is something similar to your example here in the docs.

    I think there should be a demo in Enable color on dark section.

  13. felipeLx commented on Oct 11, 2021

    @felipeLx

    hi, newbie question. In the case that want to refactor the code, can the issue be fixed with the line of code below?

    createTheme({
    .
    .
    palette: {
    ...children.color,
    })

  14. Kaid00 commented on Oct 11, 2021

    @Kaid00

    I think this can be improved by adding one example in the docs. I marked this as "Good First Issue" in case anyone wants to work on it.

    @siriwatknp I would like to work on it, could you please clarify what do you have in mind?
    As @oliviertassinari said, there is something similar to your example here in the docs.

    I think there should be a demo in Enable color on dark section.

    Yes that would give more clarity to developers, I would like to work on it

  15. siriwatknp commented on Oct 12, 2021

    @siriwatknp
    Member

    @Kaid00 👍. Awesome, go ahead. Feel free to tag me as a reviewer when you have a PR up.

  16. Wimukti commented on Oct 18, 2021

    @Wimukti
    Contributor

    Hi everyone. I also found that including a demo would give more clarity to developers as I faced the same thing on finding a solution for this same issue. So I have added a demo to this section in the documentation and created a pull request.
    @siriwatknp can you review it, please. #29129

    Capture1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsgood first issuescope: app bar

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions