Skip to content

Commit ed09506

Browse files
committed
perf(material/checkbox): Optimize more expensive selectors
1 parent c1ff40f commit ed09506

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/material/checkbox/_checkbox-common.scss

+22-13
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,17 @@ $_fallback-size: 40px;
119119
border-color: transparent;
120120
}
121121

122-
.mdc-checkbox:hover .mdc-checkbox__native-control:not(:checked) ~ .mdc-checkbox__background,
122+
// stylelint-disable selector-combinator-space-before
123+
.mdc-checkbox:hover > .mdc-checkbox__native-control:not(:checked) ~ .mdc-checkbox__background,
123124
.mdc-checkbox:hover
124-
.mdc-checkbox__native-control:not(:indeterminate) ~ .mdc-checkbox__background {
125+
> .mdc-checkbox__native-control:not(:indeterminate) ~ .mdc-checkbox__background {
125126
@include token-utils.create-token-slot(border-color, unselected-hover-icon-color);
126127
background-color: transparent;
127128
}
129+
// stylelint-enable selector-combinator-space-before
128130

129-
.mdc-checkbox:hover .mdc-checkbox__native-control:checked ~ .mdc-checkbox__background,
130-
.mdc-checkbox:hover .mdc-checkbox__native-control:indeterminate ~ .mdc-checkbox__background {
131+
.mdc-checkbox:hover > .mdc-checkbox__native-control:checked ~ .mdc-checkbox__background,
132+
.mdc-checkbox:hover > .mdc-checkbox__native-control:indeterminate ~ .mdc-checkbox__background {
131133
@include token-utils.create-token-slot(border-color, selected-hover-icon-color);
132134
@include token-utils.create-token-slot(background-color, selected-hover-icon-color);
133135
}
@@ -147,7 +149,7 @@ $_fallback-size: 40px;
147149

148150
// Needs extra specificity to override the focus, hover, active states.
149151
.mdc-checkbox--disabled.mat-mdc-checkbox-disabled-interactive {
150-
.mdc-checkbox:hover .mdc-checkbox__native-control ~ .mdc-checkbox__background,
152+
.mdc-checkbox:hover > .mdc-checkbox__native-control ~ .mdc-checkbox__background,
151153
.mdc-checkbox .mdc-checkbox__native-control:focus ~ .mdc-checkbox__background,
152154
.mdc-checkbox__background {
153155
@include token-utils.create-token-slot(border-color, disabled-unselected-icon-color);
@@ -306,31 +308,31 @@ $_fallback-size: 40px;
306308
transition: border-color $_transition-duration $_enter-curve,
307309
background-color $_transition-duration $_enter-curve;
308310

309-
.mdc-checkbox__checkmark-path {
311+
> .mdc-checkbox__checkmark > .mdc-checkbox__checkmark-path {
310312
stroke-dashoffset: 0;
311313
}
312314
}
313315

314316
.mdc-checkbox__native-control:checked ~ .mdc-checkbox__background {
315-
.mdc-checkbox__checkmark {
317+
> .mdc-checkbox__checkmark {
316318
transition: opacity $_transition-duration * 2 $_enter-curve,
317319
transform $_transition-duration * 2 $_enter-curve;
318320
opacity: 1;
319321
}
320322

321-
.mdc-checkbox__mixedmark {
323+
> .mdc-checkbox__mixedmark {
322324
transform: scaleX(1) rotate(-45deg);
323325
}
324326
}
325327
.mdc-checkbox__native-control:indeterminate ~ .mdc-checkbox__background {
326-
.mdc-checkbox__checkmark {
328+
> .mdc-checkbox__checkmark {
327329
transform: rotate(45deg);
328330
opacity: 0;
329331
transition: opacity $_transition-duration $_exit-curve,
330332
transform $_transition-duration $_exit-curve;
331333
}
332334

333-
.mdc-checkbox__mixedmark {
335+
> .mdc-checkbox__mixedmark {
334336
transform: scaleX(1) rotate(0deg);
335337
opacity: 1;
336338
}
@@ -445,8 +447,15 @@ $_fallback-size: 40px;
445447

446448
// Conditionally disables the animations of the checkbox.
447449
@mixin checkbox-noop-animations() {
448-
&._mat-animation-noopable .mdc-checkbox {
449-
*, *::before {
450+
&._mat-animation-noopable > .mat-internal-form-field > .mdc-checkbox {
451+
> .mat-mdc-checkbox-touch-target,
452+
> .mdc-checkbox__native-control,
453+
> .mdc-checkbox__ripple,
454+
> .mat-mdc-checkbox-ripple::before,
455+
> .mdc-checkbox__background,
456+
> .mdc-checkbox__background > .mdc-checkbox__checkmark,
457+
> .mdc-checkbox__background > .mdc-checkbox__checkmark > .mdc-checkbox__checkmark-path,
458+
> .mdc-checkbox__background > .mdc-checkbox__mixedmark {
450459
transition: none !important;
451460
animation: none !important;
452461
}
@@ -465,7 +474,7 @@ $_fallback-size: 40px;
465474
);
466475
}
467476

468-
> .mat-mdc-checkbox-ripple .mat-ripple-element {
477+
> .mat-mdc-checkbox-ripple > .mat-ripple-element {
469478
@include token-utils.create-token-slot(
470479
background-color,
471480
unselected-hover-state-layer-color

0 commit comments

Comments
 (0)