Skip to content

Commit 152c60b

Browse files
committedJan 25, 2022
perf(material-experimental/mdc-radio): reduce bundle size (#24267)
Reduces the bundle size of the MDC-based radio button by excluding styles we don't need. This shaves off ~15kb from the dev app bundle, although I believe that the styles are duplicated there so the real reduction is likely ~7.5kb. (cherry picked from commit e6c3379)
1 parent 81b6a81 commit 152c60b

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed
 

‎src/material-experimental/mdc-radio/_radio-theme.scss

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
@mixin _color-palette($color-palette) {
1111
@include mdc-radio-theme.theme((
1212
selected-focus-icon-color: $color-palette,
13-
selected-focus-state-layer-color: $color-palette,
1413
selected-hover-icon-color: $color-palette,
15-
selected-hover-state-layer-color: $color-palette,
1614
selected-icon-color: $color-palette,
1715
selected-pressed-icon-color: $color-palette,
18-
selected-pressed-state-layer-color: $color-palette,
1916
));
2017

2118
// TODO(crisbeto): this should be included by MDC's `theme-styles`, but it isn't currently.
@@ -39,12 +36,9 @@
3936
disabled-selected-icon-color: mdc-theme-color.$on-surface,
4037
disabled-unselected-icon-color: mdc-theme-color.$on-surface,
4138
unselected-focus-icon-color: $on-surface,
42-
unselected-focus-state-layer-color: $on-surface,
4339
unselected-hover-icon-color: $on-surface,
44-
unselected-hover-state-layer-color: $on-surface,
4540
unselected-icon-color: $on-surface,
4641
unselected-pressed-icon-color: $on-surface,
47-
unselected-pressed-state-layer-color: $on-surface,
4842
));
4943

5044
&.mat-primary {

‎src/material-experimental/mdc-radio/radio.html

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<div class="mdc-radio__outer-circle"></div>
2020
<div class="mdc-radio__inner-circle"></div>
2121
</div>
22-
<div class="mdc-radio__ripple"></div>
2322
<div mat-ripple class="mat-radio-ripple mat-mdc-focus-indicator"
2423
[matRippleTrigger]="formField"
2524
[matRippleDisabled]="_isRippleDisabled()"

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

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use 'sass:map';
12
@use '@material/radio/radio' as mdc-radio;
23
@use '@material/radio/radio-theme' as mdc-radio-theme;
34
@use '@material/form-field' as mdc-form-field;
@@ -7,22 +8,31 @@
78
@use '../../material/core/style/layout-common';
89

910
@include mdc-helpers.disable-fallback-declarations {
10-
@include mdc-radio.without-ripple($query: mdc-helpers.$mat-base-styles-without-animation-query);
11+
@include mdc-radio.static-styles($query: mdc-helpers.$mat-base-styles-query);
1112
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-base-styles-query);
1213
}
1314

1415
.mat-mdc-radio-button {
15-
&:not(._mat-animation-noopable) {
16-
@include mdc-helpers.disable-fallback-declarations {
17-
@include mdc-radio.without-ripple($query: animation);
18-
}
19-
}
20-
2116
.mdc-radio {
2217
// MDC theme styles also include structural styles so we have to include the theme at least
2318
// once here. The values will be overwritten by our own theme file afterwards.
2419
@include mdc-helpers.disable-fallback-declarations {
25-
@include mdc-radio-theme.theme-styles(mdc-radio-theme.$light-theme);
20+
@include mdc-radio-theme.theme-styles(map.merge(mdc-radio-theme.$light-theme, (
21+
// Exclude the styles we don't need.
22+
selected-focus-state-layer-color: null,
23+
selected-focus-state-layer-opacity: null,
24+
selected-hover-state-layer-color: null,
25+
selected-hover-state-layer-opacity: null,
26+
selected-pressed-state-layer-color: null,
27+
selected-pressed-state-layer-opacity: null,
28+
unselected-focus-icon-color: null,
29+
unselected-focus-state-layer-color: null,
30+
unselected-focus-state-layer-opacity: null,
31+
unselected-hover-state-layer-color: null,
32+
unselected-hover-state-layer-opacity: null,
33+
unselected-pressed-state-layer-color: null,
34+
unselected-pressed-state-layer-opacity: null,
35+
)));
2636
}
2737
}
2838

@@ -33,10 +43,19 @@
3343
pointer-events: none;
3444
border-radius: 50%;
3545

36-
.mat-ripple-element:not(.mat-radio-persistent-ripple) {
46+
.mat-ripple-element {
3747
opacity: mdc-radio-theme.$ripple-opacity;
3848
}
3949
}
50+
51+
&._mat-animation-noopable {
52+
.mdc-radio__background::before,
53+
.mdc-radio__outer-circle,
54+
.mdc-radio__inner-circle {
55+
// Needs to be `!important`, because MDC's selectors are really specific.
56+
transition: none !important;
57+
}
58+
}
4059
}
4160

4261
// Element used to provide a larger tap target for users on touch devices.

0 commit comments

Comments
 (0)
Please sign in to comment.