Skip to content

Commit 4b594fb

Browse files
kseamonok7sai
authored andcommitted
perf(material/checkbox): Use > combinator for hover selector (angular#32586)
(cherry picked from commit 8cff9c5)
1 parent 6080def commit 4b594fb

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

src/material/checkbox/_checkbox-common.scss

Lines changed: 50 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,31 @@ $_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+
// stylelint-disable-next-line max-line-length
299+
animation: mdc-checkbox-indeterminate-checked-checkmark $_indeterminate-change-duration linear;
287300
transition: none;
288301
}
289302

290303
.mdc-checkbox__mixedmark {
291-
animation: mdc-checkbox-indeterminate-checked-mixedmark
292-
$_indeterminate-change-duration linear;
304+
// stylelint-disable-next-line max-line-length
305+
animation: mdc-checkbox-indeterminate-checked-mixedmark $_indeterminate-change-duration linear;
293306
transition: none;
294307
}
295308
}
296309

297310
.mdc-checkbox--anim-indeterminate-unchecked {
298311
.mdc-checkbox__mixedmark {
299-
animation: mdc-checkbox-indeterminate-unchecked-mixedmark
300-
$_indeterminate-change-duration * 0.6 linear;
312+
animation: mdc-checkbox-indeterminate-unchecked-mixedmark $_indeterminate-change-duration *
313+
0.6 linear;
301314
transition: none;
302315
}
303316
}
304317

305318
.mdc-checkbox__native-control:checked ~ .mdc-checkbox__background,
306319
.mdc-checkbox__native-control:indeterminate ~ .mdc-checkbox__background {
307-
transition: border-color $_transition-duration $_enter-curve,
308-
background-color $_transition-duration $_enter-curve;
320+
transition:
321+
border-color $_transition-duration $_enter-curve,
322+
background-color $_transition-duration $_enter-curve;
309323

310324
> .mdc-checkbox__checkmark > .mdc-checkbox__checkmark-path {
311325
stroke-dashoffset: 0;
@@ -314,8 +328,9 @@ $_fallback-size: 40px;
314328

315329
.mdc-checkbox__native-control:checked ~ .mdc-checkbox__background {
316330
> .mdc-checkbox__checkmark {
317-
transition: opacity $_transition-duration * 2 $_enter-curve,
318-
transform $_transition-duration * 2 $_enter-curve;
331+
transition:
332+
opacity $_transition-duration * 2 $_enter-curve,
333+
transform $_transition-duration * 2 $_enter-curve;
319334
opacity: 1;
320335
}
321336

@@ -327,8 +342,9 @@ $_fallback-size: 40px;
327342
> .mdc-checkbox__checkmark {
328343
transform: rotate(45deg);
329344
opacity: 0;
330-
transition: opacity $_transition-duration $_exit-curve,
331-
transform $_transition-duration $_exit-curve;
345+
transition:
346+
opacity $_transition-duration $_exit-curve,
347+
transform $_transition-duration $_exit-curve;
332348
}
333349

334350
> .mdc-checkbox__mixedmark {
@@ -338,7 +354,8 @@ $_fallback-size: 40px;
338354
}
339355

340356
@keyframes mdc-checkbox-unchecked-checked-checkmark-path {
341-
0%, 50% {
357+
0%,
358+
50% {
342359
stroke-dashoffset: $_path-length;
343360
}
344361

@@ -352,7 +369,8 @@ $_fallback-size: 40px;
352369
}
353370

354371
@keyframes mdc-checkbox-unchecked-indeterminate-mixedmark {
355-
0%, 68.2% {
372+
0%,
373+
68.2% {
356374
transform: scaleX(0);
357375
}
358376

@@ -437,7 +455,8 @@ $_fallback-size: 40px;
437455
opacity: 1;
438456
}
439457

440-
32.8%, 100% {
458+
32.8%,
459+
100% {
441460
transform: scaleX(0);
442461
opacity: 0;
443462
}
@@ -501,7 +520,7 @@ $_fallback-size: 40px;
501520
}
502521
}
503522

504-
&:hover .mdc-checkbox__native-control:checked {
523+
&:hover > .mdc-checkbox__native-control:checked {
505524
& + .mdc-checkbox__ripple {
506525
opacity: token-utils.slot(checkbox-selected-hover-state-layer-opacity, $fallbacks);
507526
background-color: token-utils.slot(checkbox-selected-hover-state-layer-color, $fallbacks);

0 commit comments

Comments
 (0)