Skip to content

Commit a8e40ec

Browse files
authored
fix(material/core): correctly identify color input (#29909)
1 parent 0064b42 commit a8e40ec

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/material/core/theming/_config-validation.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// Validates that the given object is an M3 palette.
3030
/// @param {*} $palette The object to test
3131
/// @return {Boolean|null} null if it is a valid M3 palette, else true.
32-
@function _validate-palette($palette) {
32+
@function validate-palette($palette) {
3333
@if not meta.type-of($palette) == 'map' {
3434
@return true;
3535
}
@@ -108,7 +108,7 @@
108108
}
109109
@each $palette in (primary, secondary, tertiary) {
110110
@if $config and map.has-key($config, $palette) {
111-
$err: _validate-palette(map.get($config, $palette));
111+
$err: validate-palette(map.get($config, $palette));
112112
@if $err {
113113
@return (
114114
#{'Expected $config.#{$palette} to be a valid M3 palette. Got:'}

src/material/core/tokens/_m3-system.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use '../style/elevation';
22
@use '../style/sass-utils';
3+
@use '../theming/config-validation';
34
@use '../theming/definition';
45
@use './m3/definitions';
56
@use 'sass:map';
@@ -44,14 +45,17 @@ $_system-level-prefix: sys;
4445
$color: map.get($config, color);
4546
$color-config: null;
4647
@if ($color) {
48+
// validate-palette returns null if it is a valid M3 palette
49+
$is-palette: config-validation.validate-palette($color) == null;
50+
4751
// Default to "color-scheme" theme type if the config's color does not provide one.
48-
@if (meta.type-of($color) == 'map' and not map.has-key($color, theme-type)) {
52+
@if (not $is-palette and not map.has-key($color, theme-type)) {
4953
$color: map.set($color, theme-type, color-scheme);
5054
}
5155

52-
$color-config: if(meta.type-of($color) == 'map',
53-
definition.define-colors($color),
54-
definition.define-colors((primary: $color, theme-type: color-scheme)));
56+
$color-config: if($is-palette,
57+
definition.define-colors((primary: $color, theme-type: color-scheme)),
58+
definition.define-colors($color));
5559
@include system-level-colors($color-config, $overrides, $_system-fallback-prefix);
5660
@include system-level-elevation($color-config, $overrides, $_system-fallback-prefix);
5761
}

0 commit comments

Comments
 (0)