File tree Expand file tree Collapse file tree 3 files changed +37
-12
lines changed
Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Original file line number Diff line number Diff line change 1616@use ' ./tokens/m2/mat/full-pseudo-checkbox' as tokens-mat-full-pseudo-checkbox ;
1717@use ' ./tokens/m2/mat/minimal-pseudo-checkbox' as tokens-mat-minimal-pseudo-checkbox ;
1818
19+ $_has-inserted-loaded-marker : false;
20+
21+ @mixin _theme-loaded-marker {
22+ @if not $_has-inserted-loaded-marker {
23+ $_has-inserted-loaded-marker : true !global;
24+
25+ // Marker that is used to determine whether the user has added a theme to their page.
26+ // Needs to be generated at the root, because themes may be nested inside classes.
27+ @at-root {
28+ .mat-theme-loaded-marker {
29+ display : none ;
30+ }
31+ }
32+ }
33+ }
34+
1935@mixin base ($theme ) {
2036 @if inspection .get-theme-version ($theme ) == 1 {
2137 @include _theme-from-tokens (inspection .get-theme-tokens ($theme , base ));
2642 @include optgroup-theme .base ($theme );
2743 @include pseudo-checkbox-theme .base ($theme );
2844 }
45+
46+ // The marker is a concrete style no matter which Material version we're targeting.
47+ @include _theme-loaded-marker ;
2948}
3049
3150@mixin color ($theme ) {
5473 }
5574 }
5675 }
57-
58- // TODO(crisbeto): move this into the base.
59- // Marker that is used to determine whether the user has added a theme to their page.
60- @at-root {
61- .mat-theme-loaded-marker {
62- display : none ;
63- }
64- }
6576}
6677
6778@mixin typography ($theme ) {
127138 }
128139 }
129140 }
141+
142+ // The marker is a concrete style no matter which Material version we're targeting.
143+ @include _theme-loaded-marker ;
130144}
131145
132146@mixin _theme-from-tokens ($tokens , $options ...) {
Original file line number Diff line number Diff line change 1- import { parse } from 'postcss' ;
1+ import { parse , Rule } from 'postcss' ;
22import { compileString } from 'sass' ;
33import { runfiles } from '@bazel/runfiles' ;
44import * as path from 'path' ;
@@ -68,14 +68,18 @@ describe('M3 theme', () => {
6868 root . walkRules ( rule => {
6969 selectors . push ( rule . selector ) ;
7070 } ) ;
71- expect ( selectors ) . toEqual ( [ 'html' ] ) ;
71+ expect ( selectors ) . toEqual ( [ 'html' , '.mat-theme-loaded-marker' ] ) ;
7272 } ) ;
7373
7474 it ( 'should only emit CSS variables' , ( ) => {
7575 const root = parse ( transpile ( `html { @include mat.all-component-themes($theme); }` ) ) ;
7676 const nonVarProps : string [ ] = [ ] ;
7777 root . walkDecls ( decl => {
78- if ( ! decl . prop . startsWith ( '--' ) ) {
78+ if (
79+ ! decl . prop . startsWith ( '--' ) &&
80+ // Skip the theme loaded marker since it can't be a variable.
81+ ( decl . parent as Rule ) . selector !== '.mat-theme-loaded-marker'
82+ ) {
7983 nonVarProps . push ( decl . prop ) ;
8084 }
8185 } ) ;
Original file line number Diff line number Diff line change @@ -472,7 +472,14 @@ describe('theming inspection api', () => {
472472 div {
473473 @include mat.all-component-themes($theme);
474474 }` ) ;
475- expect ( css ) . toBe ( '' ) ;
475+ expect ( css ) . toBe (
476+ [
477+ // The marker is always included.
478+ `.mat-theme-loaded-marker {` ,
479+ ` display: none;` ,
480+ `}` ,
481+ ] . join ( '\n' ) ,
482+ ) ;
476483 } ) ;
477484 } ) ;
478485} ) ;
You can’t perform that action at this time.
0 commit comments