Skip to content

Commit d1ee78d

Browse files
committed
perf(material/button): Use child rather than descendant selectors.
1 parent 7c57f82 commit d1ee78d

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/material/button/_button-base.scss

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
-webkit-tap-highlight-color: transparent;
1111

1212
// The ripple container should match the bounds of the entire button.
13-
.mat-mdc-button-ripple,
14-
.mat-mdc-button-persistent-ripple,
15-
.mat-mdc-button-persistent-ripple::before {
13+
> .mat-mdc-button-ripple,
14+
> .mat-mdc-button-persistent-ripple,
15+
> .mat-mdc-button-persistent-ripple::before {
1616
@include layout-common.fill;
1717

1818
// Disable pointer events for the ripple container and state overlay because the container
@@ -29,61 +29,61 @@
2929

3030
// This style used to be applied by the MatRipple
3131
// directive, which is no longer attached to this element.
32-
.mat-mdc-button-ripple {
32+
> .mat-mdc-button-ripple {
3333
overflow: hidden;
3434
}
3535

3636
// We use ::before so that we can reuse some of MDC's theming.
37-
.mat-mdc-button-persistent-ripple::before {
37+
> .mat-mdc-button-persistent-ripple::before {
3838
content: '';
3939
opacity: 0;
4040
}
4141

4242
// The content should appear over the state and ripple layers, otherwise they may adversely affect
4343
// the accessibility of the text content.
44-
.mdc-button__label,
45-
.mat-icon {
44+
> .mdc-button__label,
45+
> .mat-icon {
4646
z-index: 1;
4747
position: relative;
4848
}
4949

5050
// The focus indicator should match the bounds of the entire button.
51-
.mat-focus-indicator {
51+
> .mat-focus-indicator {
5252
@include layout-common.fill();
5353
}
5454

55-
&:focus .mat-focus-indicator::before {
55+
&:focus > .mat-focus-indicator::before {
5656
content: '';
5757
}
5858
}
5959

6060
@mixin mat-private-button-ripple($prefix, $slots) {
6161
@include token-utils.use-tokens($prefix, $slots) {
62-
.mat-ripple-element {
62+
> .mat-ripple-element {
6363
@include token-utils.create-token-slot(background-color, ripple-color);
6464
}
6565

66-
.mat-mdc-button-persistent-ripple::before {
66+
> .mat-mdc-button-persistent-ripple::before {
6767
@include token-utils.create-token-slot(background-color, state-layer-color);
6868
}
6969

70-
&.mat-mdc-button-disabled .mat-mdc-button-persistent-ripple::before {
70+
&.mat-mdc-button-disabled > .mat-mdc-button-persistent-ripple::before {
7171
@include token-utils.create-token-slot(background-color, disabled-state-layer-color);
7272
}
7373

74-
&:hover .mat-mdc-button-persistent-ripple::before {
74+
&:hover > .mat-mdc-button-persistent-ripple::before {
7575
@include token-utils.create-token-slot(opacity, hover-state-layer-opacity);
7676
}
7777

7878
&.cdk-program-focused,
7979
&.cdk-keyboard-focused,
8080
&.mat-mdc-button-disabled-interactive:focus {
81-
.mat-mdc-button-persistent-ripple::before {
81+
> .mat-mdc-button-persistent-ripple::before {
8282
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
8383
}
8484
}
8585

86-
&:active .mat-mdc-button-persistent-ripple::before {
86+
&:active > .mat-mdc-button-persistent-ripple::before {
8787
@include token-utils.create-token-slot(opacity, pressed-state-layer-opacity);
8888
}
8989
}
@@ -116,7 +116,7 @@
116116
}
117117

118118
@mixin mat-private-button-touch-target($is-square, $prefix, $slots) {
119-
.mat-mdc-button-touch-target {
119+
> .mat-mdc-button-touch-target {
120120
position: absolute;
121121
top: 50%;
122122
height: 48px;

src/material/button/button.scss

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
display: none;
5656
}
5757

58-
.mdc-button__label {
58+
> .mdc-button__label {
5959
position: relative;
6060
}
6161
}
@@ -78,7 +78,7 @@
7878
@include token-utils.create-token-slot(text-transform, label-text-transform);
7979
@include token-utils.create-token-slot(font-weight, label-text-weight);
8080

81-
&, .mdc-button__ripple {
81+
&, > .mdc-button__ripple {
8282
@include token-utils.create-token-slot(border-radius, container-shape);
8383
}
8484

@@ -137,7 +137,7 @@
137137
@include token-utils.create-token-slot(background-color, container-color);
138138
}
139139

140-
&, .mdc-button__ripple {
140+
&, > .mdc-button__ripple {
141141
@include token-utils.create-token-slot(border-radius, container-shape);
142142
}
143143

@@ -190,7 +190,7 @@
190190
@include token-utils.create-token-slot(background-color, container-color);
191191
}
192192

193-
&, .mdc-button__ripple {
193+
&, > .mdc-button__ripple {
194194
@include token-utils.create-token-slot(border-radius, container-shape);
195195
}
196196

@@ -302,8 +302,8 @@
302302
// In order to work around this issue by *not* hiding overflow, we adjust the child elements
303303
// to fully cover the actual button element. This means that the border-radius would be correct
304304
// then. See: https://github.com/angular/components/issues/13738
305-
.mat-mdc-outlined-button .mat-mdc-button-ripple,
306-
.mat-mdc-outlined-button .mdc-button__ripple {
305+
.mat-mdc-outlined-button > .mat-mdc-button-ripple,
306+
.mat-mdc-outlined-button > .mdc-button__ripple {
307307
$offset: -1px;
308308
top: $offset;
309309
left: $offset;
@@ -315,15 +315,15 @@
315315
// the focus indicator is sufficiently contrastive and renders appropriately.
316316
.mat-mdc-unelevated-button,
317317
.mat-mdc-raised-button {
318-
.mat-focus-indicator::before {
318+
> .mat-focus-indicator::before {
319319
$default-border-width: focus-indicators-private.$default-border-width;
320320
$border-width: var(--mat-focus-indicator-border-width, #{$default-border-width});
321321
$offset: calc(#{$border-width} + 2px);
322322
margin: calc(#{$offset} * -1);
323323
}
324324
}
325325

326-
.mat-mdc-outlined-button .mat-focus-indicator::before {
326+
.mat-mdc-outlined-button > .mat-focus-indicator::before {
327327
$default-border-width: focus-indicators-private.$default-border-width;
328328
$border-width: var(--mat-focus-indicator-border-width, #{$default-border-width});
329329
$offset: calc(#{$border-width} + 3px);

src/material/button/fab.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
// However, Angular Material expects a `mat-icon` instead. The following
7676
// mixin will style the icons appropriately.
7777
// stylelint-disable-next-line selector-class-pattern
78-
.mat-icon, .material-icons {
78+
> .mat-icon, > .material-icons {
7979
transition: transform 180ms 90ms cubic-bezier(0, 0, 0.2, 1);
8080
fill: currentColor;
8181
will-change: transform;
8282
}
8383

84-
.mat-focus-indicator::before {
84+
> .mat-focus-indicator::before {
8585
$default-border-width: focus-indicators-private.$default-border-width;
8686
$border-width: var(--mat-focus-indicator-border-width, #{$default-border-width});
8787
$offset: calc(#{$border-width} + 2px);
@@ -209,7 +209,7 @@
209209

210210
// All FABs are square except the extended ones so we
211211
// need to set the touch target back to full-width.
212-
.mat-mdc-button-touch-target {
212+
> .mat-mdc-button-touch-target {
213213
width: 100%;
214214
}
215215
}

src/material/button/icon-button.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
}
7373
}
7474

75-
.mat-mdc-button-persistent-ripple {
75+
> .mat-mdc-button-persistent-ripple {
7676
border-radius: 50%;
7777
}
7878

0 commit comments

Comments
 (0)