Skip to content

Commit 4350552

Browse files
authored
perf(multiple): don't emit fallbacks for CSS variables in experimental components (#23912)
Reworks the theming for the MDC-based components so that it doesn't emit fallback values for CSS variables. This trims ~27kb from the dev app theme. Also wraps the structural styles of the MDC-based radio button and slide toggle who have been converted to the new MDC theming API.
1 parent 4be9a6e commit 4350552

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

src/material-experimental/mdc-helpers/_mdc-helpers.scss

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use '@material/feature-targeting' as mdc-feature-targeting;
66
@use '@material/typography' as mdc-typography;
77
@use '@material/theme/theme-color' as mdc-theme-color;
8+
@use '@material/theme/css' as mdc-theme-css;
89
@use 'sass:map';
910
@use '../../material/core/theming/theming';
1011
@use '../../material/core/typography/typography';
@@ -169,7 +170,9 @@ $mat-typography-mdc-level-mappings: (
169170
);
170171

171172
// Apply given rules.
172-
@content;
173+
@include disable-fallback-declarations {
174+
@content;
175+
}
173176

174177
// Reset the original values.
175178
mdc-theme-color.$primary: $orig-primary;
@@ -196,8 +199,18 @@ $mat-typography-mdc-level-mappings: (
196199
}
197200

198201
// Apply given rules.
199-
@content;
202+
@include disable-fallback-declarations {
203+
@content;
204+
}
200205

201206
// Reset the original values.
202207
mdc-typography.$styles: $orig-mdc-typography-styles;
203208
}
209+
210+
// Disables MDC's CSS custom property fallbacks for the specified mixin content.
211+
@mixin disable-fallback-declarations {
212+
$previous-value: mdc-theme-css.$enable-fallback-declarations;
213+
mdc-theme-css.$enable-fallback-declarations: false;
214+
@content;
215+
mdc-theme-css.$enable-fallback-declarations: $previous-value;
216+
}

src/material-experimental/mdc-radio/radio.scss

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
@use '../../cdk/a11y';
77
@use '../../material/core/style/layout-common';
88

9-
@include mdc-radio.without-ripple($query: mdc-helpers.$mat-base-styles-without-animation-query);
10-
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-base-styles-query);
9+
@include mdc-helpers.disable-fallback-declarations {
10+
@include mdc-radio.without-ripple($query: mdc-helpers.$mat-base-styles-without-animation-query);
11+
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-base-styles-query);
12+
}
1113

1214
.mat-mdc-radio-button {
1315
&:not(._mat-animation-noopable) {
14-
@include mdc-radio.without-ripple($query: animation);
16+
@include mdc-helpers.disable-fallback-declarations {
17+
@include mdc-radio.without-ripple($query: animation);
18+
}
1519
}
1620

1721
.mdc-radio {
1822
// MDC theme styles also include structural styles so we have to include the theme at least
1923
// once here. The values will be overwritten by our own theme file afterwards.
20-
@include mdc-radio-theme.theme-styles(mdc-radio-theme.$light-theme);
24+
@include mdc-helpers.disable-fallback-declarations {
25+
@include mdc-radio-theme.theme-styles(mdc-radio-theme.$light-theme);
26+
}
2127
}
2228

2329
// This is necessary because we do not depend on MDC's ripple, but have our own that should be
@@ -35,9 +41,11 @@
3541

3642
// Element used to provide a larger tap target for users on touch devices.
3743
.mat-mdc-radio-touch-target {
38-
@include mdc-touch-target.touch-target(
39-
$set-width: true,
40-
$query: mdc-helpers.$mat-base-styles-query);
44+
@include mdc-helpers.disable-fallback-declarations {
45+
@include mdc-touch-target.touch-target(
46+
$set-width: true,
47+
$query: mdc-helpers.$mat-base-styles-query);
48+
}
4149

4250
[dir='rtl'] & {
4351
left: 0;

src/material-experimental/mdc-slide-toggle/slide-toggle.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
@use '../../material/core/style/layout-common';
99
@use '../../cdk/a11y';
1010

11-
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-base-styles-query);
12-
@include mdc-switch.static-styles-without-ripple;
11+
@include mdc-helpers.disable-fallback-declarations {
12+
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-base-styles-query);
13+
@include mdc-switch.static-styles-without-ripple;
14+
}
1315

1416
.mat-mdc-slide-toggle {
1517
display: inline-block;
@@ -20,7 +22,9 @@
2022
.mdc-switch {
2123
// MDC theme styles also include structural styles so we have to include the theme at least
2224
// once here. The values will be overwritten by our own theme file afterwards.
23-
@include mdc-switch-theme.theme-styles(mdc-switch-theme.$light-theme);
25+
@include mdc-helpers.disable-fallback-declarations {
26+
@include mdc-switch-theme.theme-styles(mdc-switch-theme.$light-theme);
27+
}
2428
}
2529

2630
// The ripple needs extra specificity so the base ripple styling doesn't override its `position`.

src/material-experimental/mdc-tabs/_tabs-common.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ $mat-tab-animation-duration: 500ms !default;
1010

1111
// Combines the various structural styles we need for the tab group and tab nav bar.
1212
@mixin structural-styles {
13-
@include mdc-tab.without-ripple($query: mdc-helpers.$mat-base-styles-query);
14-
@include mdc-tab-indicator.core-styles($query: mdc-helpers.$mat-base-styles-query);
13+
@include mdc-helpers.disable-fallback-declarations {
14+
@include mdc-tab.without-ripple($query: mdc-helpers.$mat-base-styles-query);
15+
@include mdc-tab-indicator.core-styles($query: mdc-helpers.$mat-base-styles-query);
16+
}
1517

1618
.mat-mdc-tab-ripple {
1719
position: absolute;

0 commit comments

Comments
 (0)