Skip to content

fix(material/checkbox): set token values on the element where theme is @included #27114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/material/checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'sass:map';
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
@use '@material/form-field' as mdc-form-field;
@use '../core/style/sass-utils';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use '../core/mdc-helpers/mdc-helpers';
Expand All @@ -12,9 +13,11 @@
$warn: map.get($config, warn);
$foreground: map.get($config, foreground);

.mat-mdc-checkbox {
@include sass-utils.current-selector-or-root() {
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($config));
}

.mat-mdc-checkbox {
&.mat-primary {
$primary-config: map.merge($config, (accent: $primary));
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($primary-config));
Expand All @@ -40,9 +43,12 @@
@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));
.mat-mdc-checkbox {

@include sass-utils.current-selector-or-root() {
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-typography-tokens($config));
}

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

.mat-mdc-checkbox {
@include sass-utils.current-selector-or-root() {
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-density-tokens($density-scale));
}

Expand Down
2 changes: 1 addition & 1 deletion src/material/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
}
}

.mat-mdc-checkbox {
html {
// Add default values for MDC checkbox tokens that aren't outputted by the theming API.
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-unthemable-tokens());
}
Expand Down
7 changes: 7 additions & 0 deletions src/material/core/style/_sass-utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Include content under the current selector (&) or the document root if there is no current
// selector.
@mixin current-selector-or-root($root: html) {
@at-root #{& or $root} {
@content;
}
}
12 changes: 9 additions & 3 deletions src/material/core/theming/tests/theming-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,15 @@ describe('theming api', () => {
return;
}
node.selectors.forEach(selector => {
// Only check selectors that match the specified base selector.
if (baseSelector && !baseSelectorRegex.test(selector)) {
return;
if (baseSelector && selector === baseSelector) {
// Styles emitted directly to the baseSelector are emitted to html
// when there is no baseSelector.
selector = 'html';
} else {
// Only check selectors that match the specified base selector.
if (baseSelector && !baseSelectorRegex.test(selector)) {
return;
}
}
selector = selector.replace(baseSelectorRegex, '');
const matchingRule = knownDensitySelectors.get(selector);
Expand Down