Skip to content

Commit 0d19aa6

Browse files
committed
perf(material/checkbox): Use > combinator for hover selector
1 parent ef53e73 commit 0d19aa6

File tree

1 file changed

+48
-31
lines changed

1 file changed

+48
-31
lines changed

src/material/checkbox/_checkbox-common.scss

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ $_fallback-size: 40px;
3030
cursor: pointer;
3131
vertical-align: bottom;
3232

33-
$layer-size: token-utils.slot(checkbox-state-layer-size,
34-
$fallbacks, $fallback: $_fallback-size);
33+
$layer-size: token-utils.slot(
34+
checkbox-state-layer-size,
35+
$fallbacks,
36+
$fallback: $_fallback-size
37+
);
3538
padding: calc((#{$layer-size} - #{$_icon-size}) / 2);
3639
margin: calc((#{$layer-size} - #{$layer-size}) / 2);
3740

@@ -49,8 +52,11 @@ $_fallback-size: 40px;
4952
cursor: inherit;
5053
z-index: 1;
5154

52-
$layer-size: token-utils.slot(checkbox-state-layer-size,
53-
$fallbacks, $fallback: $_fallback-size);
55+
$layer-size: token-utils.slot(
56+
checkbox-state-layer-size,
57+
$fallbacks,
58+
$fallback: $_fallback-size
59+
);
5460
$offset: calc((#{$layer-size} - #{$layer-size}) / 2);
5561
width: $layer-size;
5662
height: $layer-size;
@@ -78,14 +84,18 @@ $_fallback-size: 40px;
7884
background-color: transparent;
7985
pointer-events: none;
8086
will-change: background-color, border-color;
81-
transition: background-color $_transition-duration $_exit-curve,
82-
border-color $_transition-duration $_exit-curve;
87+
transition:
88+
background-color $_transition-duration $_exit-curve,
89+
border-color $_transition-duration $_exit-curve;
8390

8491
// Force browser to show background-color when using the print function
8592
@include vendor-prefixes.color-adjust(exact);
8693

87-
$layer-size: token-utils.slot(checkbox-state-layer-size,
88-
$fallbacks, $fallback: $_fallback-size);
94+
$layer-size: token-utils.slot(
95+
checkbox-state-layer-size,
96+
$fallbacks,
97+
$fallback: $_fallback-size
98+
);
8999
$offset: calc((#{$layer-size} - #{$_icon-size}) / 2);
90100

91101
border-color: token-utils.slot(checkbox-unselected-icon-color, $fallbacks);
@@ -122,7 +132,8 @@ $_fallback-size: 40px;
122132
// stylelint-disable selector-combinator-space-before
123133
.mdc-checkbox:hover > .mdc-checkbox__native-control:not(:checked) ~ .mdc-checkbox__background,
124134
.mdc-checkbox:hover
125-
> .mdc-checkbox__native-control:not(:indeterminate) ~ .mdc-checkbox__background {
135+
> .mdc-checkbox__native-control:not(:indeterminate)
136+
~ .mdc-checkbox__background {
126137
border-color: token-utils.slot(checkbox-unselected-hover-icon-color, $fallbacks);
127138
background-color: transparent;
128139
}
@@ -186,7 +197,8 @@ $_fallback-size: 40px;
186197
}
187198

188199
.mdc-checkbox--disabled {
189-
&, &.mat-mdc-checkbox-disabled-interactive {
200+
&,
201+
&.mat-mdc-checkbox-disabled-interactive {
190202
.mdc-checkbox__checkmark {
191203
color: token-utils.slot(checkbox-disabled-selected-checkmark-color, $fallbacks);
192204

@@ -212,8 +224,9 @@ $_fallback-size: 40px;
212224
border-width: math.div(math.floor($_mark-stroke-size), 2);
213225
border-style: solid;
214226
opacity: 0;
215-
transition: opacity $_transition-duration $_exit-curve,
216-
transform $_transition-duration $_exit-curve;
227+
transition:
228+
opacity $_transition-duration $_exit-curve,
229+
transform $_transition-duration $_exit-curve;
217230

218231
// Always apply the color since the element becomes `opacity: 0`
219232
// when unchecked. This makes the animation look better.
@@ -225,7 +238,8 @@ $_fallback-size: 40px;
225238
}
226239

227240
.mdc-checkbox--disabled {
228-
&, &.mat-mdc-checkbox-disabled-interactive {
241+
&,
242+
&.mat-mdc-checkbox-disabled-interactive {
229243
.mdc-checkbox__mixedmark {
230244
border-color: token-utils.slot(checkbox-disabled-selected-checkmark-color, $fallbacks);
231245

@@ -248,8 +262,7 @@ $_fallback-size: 40px;
248262

249263
.mdc-checkbox--anim-unchecked-checked {
250264
.mdc-checkbox__checkmark-path {
251-
animation: mdc-checkbox-unchecked-checked-checkmark-path
252-
$_transition-duration * 2 linear;
265+
animation: mdc-checkbox-unchecked-checked-checkmark-path $_transition-duration * 2 linear;
253266
transition: none;
254267
}
255268
}
@@ -282,30 +295,29 @@ $_fallback-size: 40px;
282295

283296
.mdc-checkbox--anim-indeterminate-checked {
284297
.mdc-checkbox__checkmark {
285-
animation: mdc-checkbox-indeterminate-checked-checkmark
286-
$_indeterminate-change-duration linear;
298+
animation: mdc-checkbox-indeterminate-checked-checkmark $_indeterminate-change-duration linear;
287299
transition: none;
288300
}
289301

290302
.mdc-checkbox__mixedmark {
291-
animation: mdc-checkbox-indeterminate-checked-mixedmark
292-
$_indeterminate-change-duration linear;
303+
animation: mdc-checkbox-indeterminate-checked-mixedmark $_indeterminate-change-duration linear;
293304
transition: none;
294305
}
295306
}
296307

297308
.mdc-checkbox--anim-indeterminate-unchecked {
298309
.mdc-checkbox__mixedmark {
299-
animation: mdc-checkbox-indeterminate-unchecked-mixedmark
300-
$_indeterminate-change-duration * 0.6 linear;
310+
animation: mdc-checkbox-indeterminate-unchecked-mixedmark $_indeterminate-change-duration *
311+
0.6 linear;
301312
transition: none;
302313
}
303314
}
304315

305316
.mdc-checkbox__native-control:checked ~ .mdc-checkbox__background,
306317
.mdc-checkbox__native-control:indeterminate ~ .mdc-checkbox__background {
307-
transition: border-color $_transition-duration $_enter-curve,
308-
background-color $_transition-duration $_enter-curve;
318+
transition:
319+
border-color $_transition-duration $_enter-curve,
320+
background-color $_transition-duration $_enter-curve;
309321

310322
> .mdc-checkbox__checkmark > .mdc-checkbox__checkmark-path {
311323
stroke-dashoffset: 0;
@@ -314,8 +326,9 @@ $_fallback-size: 40px;
314326

315327
.mdc-checkbox__native-control:checked ~ .mdc-checkbox__background {
316328
> .mdc-checkbox__checkmark {
317-
transition: opacity $_transition-duration * 2 $_enter-curve,
318-
transform $_transition-duration * 2 $_enter-curve;
329+
transition:
330+
opacity $_transition-duration * 2 $_enter-curve,
331+
transform $_transition-duration * 2 $_enter-curve;
319332
opacity: 1;
320333
}
321334

@@ -327,8 +340,9 @@ $_fallback-size: 40px;
327340
> .mdc-checkbox__checkmark {
328341
transform: rotate(45deg);
329342
opacity: 0;
330-
transition: opacity $_transition-duration $_exit-curve,
331-
transform $_transition-duration $_exit-curve;
343+
transition:
344+
opacity $_transition-duration $_exit-curve,
345+
transform $_transition-duration $_exit-curve;
332346
}
333347

334348
> .mdc-checkbox__mixedmark {
@@ -338,7 +352,8 @@ $_fallback-size: 40px;
338352
}
339353

340354
@keyframes mdc-checkbox-unchecked-checked-checkmark-path {
341-
0%, 50% {
355+
0%,
356+
50% {
342357
stroke-dashoffset: $_path-length;
343358
}
344359

@@ -352,7 +367,8 @@ $_fallback-size: 40px;
352367
}
353368

354369
@keyframes mdc-checkbox-unchecked-indeterminate-mixedmark {
355-
0%, 68.2% {
370+
0%,
371+
68.2% {
356372
transform: scaleX(0);
357373
}
358374

@@ -437,7 +453,8 @@ $_fallback-size: 40px;
437453
opacity: 1;
438454
}
439455

440-
32.8%, 100% {
456+
32.8%,
457+
100% {
441458
transform: scaleX(0);
442459
opacity: 0;
443460
}
@@ -501,7 +518,7 @@ $_fallback-size: 40px;
501518
}
502519
}
503520

504-
&:hover .mdc-checkbox__native-control:checked {
521+
&:hover > .mdc-checkbox__native-control:checked {
505522
& + .mdc-checkbox__ripple {
506523
opacity: token-utils.slot(checkbox-selected-hover-state-layer-opacity, $fallbacks);
507524
background-color: token-utils.slot(checkbox-selected-hover-state-layer-color, $fallbacks);

0 commit comments

Comments
 (0)