Skip to content

[Theme] Multiple theme registration always output the first registered theme name in md-base-theme() mixin #1670

Open
@simongcc

Description

@simongcc

Steps to reproduce

Because my layout have several button and page design.
So the base code look like this:

@include md-register-theme("default", (
  primary: md-get-palette-color(grey, 700),
  secondary: md-get-palette-color(black, A200),
  accent: md-get-palette-color(white, A200),
  // theme: light // default
));

@include md-register-theme("dark-solid", (
  primary: md-get-palette-color(black, A700),
  accent: md-get-palette-color(blue, A200),
  // primary: md-get-palette-color(white, A700), // The primary color of your application
  // accent: md-get-palette-color(red, A200), // The accent or secondary color
));

What is expected?

It is expected the theme to be separately generated.
So that each theme can work in harmony.

:root {
  --md-theme-default-primary: #616161;
  --md-theme-default-accent: #fff;
  --md-theme-default-theme: "light";
  --md-theme-default-secondary: #000;
}
.md-theme-default :not(input):not(textarea)::-moz-selection {
  background-color: #fff;
  background-color: var(--md-theme-default-accent-on-background, #fff);
  color: rgba(0, 0, 0, 0.87);
  color: var(--md-theme-default-text-primary-on-accent, rgba(0, 0, 0, 0.87));
}
... skip

:root {
  --md-theme-dark-solid-primary: #000;
  --md-theme-dark-solid-accent: #448aff;
  --md-theme-dark-solid-theme: "light";
}
.md-theme-dark-solid :not(input):not(textarea)::-moz-selection {
  background-color: #fff;
  background-color: var(--md-theme-default-accent-on-background, #fff);
  color: rgba(0, 0, 0, 0.87);
  color: var(--md-theme-default-text-primary-on-accent, rgba(0, 0, 0, 0.87));
}
/* ... skip */

What is actually happening?

The outcome css look like this:
As you can see, the non-default theme is also output as "md-theme-default" in md-base-theme() mixin.

:root {
  --md-theme-default-primary: #616161;
  --md-theme-default-accent: #fff;
  --md-theme-default-theme: "light";
  --md-theme-default-secondary: #000;
}
.md-theme-default :not(input):not(textarea)::-moz-selection {
  background-color: #fff;
  background-color: var(--md-theme-default-accent-on-background, #fff);
  color: rgba(0, 0, 0, 0.87);
  color: var(--md-theme-default-text-primary-on-accent, rgba(0, 0, 0, 0.87));
}

:root {
  --md-theme-dark-solid-primary: #000;
  --md-theme-dark-solid-accent: #448aff;
  --md-theme-dark-solid-theme: "light";
}
.md-theme-default :not(input):not(textarea)::-moz-selection {
  background-color: #fff;
  background-color: var(--md-theme-default-accent-on-background, #fff);
  color: rgba(0, 0, 0, 0.87);
  color: var(--md-theme-default-text-primary-on-accent, rgba(0, 0, 0, 0.87));
}
/* ... skip */

According to my understanding, I think it is a bug and not a desired result.
The md-base-theme() mixin should generate different set of theme styles based on the registration name in md-register-theme() mixin.

Update 20180408

I have tested my node-sass for its integrity. The looping(@each) of a map is working properly without duplication.

Moreover, I have injected the following code to test $md-themes property in md-theme-component-relative mixin.

@mixin md-theme-component-relative () {
  @each $theme, $palette in $md-themes {
    $md-theme-palette: map-merge($md-theme-palette, $palette) !global;
    $md-current-theme: $theme !global;

    .md-theme-#{$theme} & {
      testname: $theme; // injected test code
      @content;
    }
  }
}

Result css

/* ... skip */
.md-theme-default :not(input):not(textarea)::-moz-selection {
  testname: default;
}
.md-theme-default :not(input):not(textarea)::selection {
  testname: default;
}

/* ... skip */
.md-theme-default :not(input):not(textarea)::-moz-selection {
  testname: default;
}
.md-theme-default :not(input):not(textarea)::selection {
  testname: default;
}
.md-theme-dark-solid :not(input):not(textarea)::-moz-selection {
  testname: dark-solid;
}
.md-theme-dark-solid :not(input):not(textarea)::selection {
  testname: dark-solid;
}

"default" (the first theme) runs twice so it appear that it is duplicated. "dark-solid" is also generated but always after "default".

I have updated the title from "Multiple theme registration always output the first registered theme name in md-base-theme() mixin"
to "Multiple theme registration output accumulated theme style inside md-theme-component and md-theme-component-relative mixin"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions