Skip to content

Commit d17bf2a

Browse files
committed
fix(material/checkbox): set token values on the element where theme is @included
For example: ``` .my-el { @include mat.checkbox-theme(...); } ``` should emit the token values on `.my-el`, not `.my-el .mat-mdc-checkbox`
1 parent 48fef66 commit d17bf2a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/material/checkbox/_checkbox-theme.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
$warn: map.get($config, warn);
1313
$foreground: map.get($config, foreground);
1414

15-
.mat-mdc-checkbox {
15+
@at-root #{& or body} {
1616
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($config));
17+
}
1718

19+
.mat-mdc-checkbox {
1820
&.mat-primary {
1921
$primary-config: map.merge($config, (accent: $primary));
2022
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($primary-config));
@@ -40,9 +42,12 @@
4042
@mixin typography($config-or-theme) {
4143
$config: typography.private-typography-to-2018-config(
4244
theming.get-typography-config($config-or-theme));
43-
.mat-mdc-checkbox {
45+
46+
@at-root #{& or body} {
4447
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-typography-tokens($config));
48+
}
4549

50+
.mat-mdc-checkbox {
4651
@include mdc-helpers.using-mdc-typography($config) {
4752
// TODO(mmalerba): Switch to static-styles, theme-styles, and theme once they're available.
4853
@include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query);
@@ -53,7 +58,7 @@
5358
@mixin density($config-or-theme) {
5459
$density-scale: theming.get-density-config($config-or-theme);
5560

56-
.mat-mdc-checkbox {
61+
@at-root #{& or body} {
5762
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-density-tokens($density-scale));
5863
}
5964

src/material/checkbox/checkbox.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
}
143143
}
144144

145-
.mat-mdc-checkbox {
145+
body {
146146
// Add default values for MDC checkbox tokens that aren't outputted by the theming API.
147147
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-unthemable-tokens());
148148
}

src/material/core/theming/tests/theming-api.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,15 @@ describe('theming api', () => {
210210
return;
211211
}
212212
node.selectors.forEach(selector => {
213-
// Only check selectors that match the specified base selector.
214-
if (baseSelector && !baseSelectorRegex.test(selector)) {
215-
return;
213+
if (baseSelector && selector === baseSelector) {
214+
// Styles emitted directly to the baseSelector are emitted to body
215+
// when there is no baseSelector.
216+
selector = 'body';
217+
} else {
218+
// Only check selectors that match the specified base selector.
219+
if (baseSelector && !baseSelectorRegex.test(selector)) {
220+
return;
221+
}
216222
}
217223
selector = selector.replace(baseSelectorRegex, '');
218224
const matchingRule = knownDensitySelectors.get(selector);

0 commit comments

Comments
 (0)