Skip to content

Commit b454e38

Browse files
authored
fix(material-experimental/button): ripples were using mat-button styles (#17069)
1 parent fdefae0 commit b454e38

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/material-experimental/mdc-button/_button-base.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import '../../material/core/style/layout-common';
2+
13
// Adds a `before` pseudo element that acts as an overlay indicator for interaction states
24
// such as focus, hover, and active.
35
@mixin _mat-button-interactive() {
@@ -10,10 +12,31 @@
1012
bottom: 0;
1113
left: 0;
1214
opacity: 0;
15+
border-radius: inherit;
1316
@content;
1417
}
1518
}
1619

20+
// The ripple container should match the bounds of the entire button.
21+
// Increase specificity for the ripple container because ripple styles are part of
22+
// the `mat-core` mixin and can potentially overwrite the absolute position of the container.
23+
@mixin _mat-button-ripple-position() {
24+
.mat-mdc-button-ripple {
25+
@include mat-fill;
26+
27+
// Disable pointer events for the ripple container and focus overlay because the container
28+
// will overlay the user content and we don't want to disable mouse events on the user content.
29+
// Pointer events can be safely disabled because the ripple trigger element is the host element.
30+
pointer-events: none;
31+
32+
// Inherit the border radius from the parent so that focus overlay and ripples don't exceed the
33+
// parent button boundaries. Note that an inherited border radius does not work properly if
34+
// the actual button element does have a border because it causes the inner content to be
35+
// smaller. We have special logic for stroked buttons to handle this scenario.
36+
border-radius: inherit;
37+
}
38+
}
39+
1740
// MDC's disabled buttons define a default cursor with pointer-events none. However, they select
1841
// :disabled for this, which does not affect anchor tags.
1942
// TODO(andrewseguin): Discuss with the MDC team about a mixin we can call for applying this style,

src/material-experimental/mdc-button/button.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ng-content select=".material-icons[iconPositionEnd], mat-icon[iconPositionEnd]">
77
</ng-content>
88

9-
<span matRipple class="mat-button-ripple"
9+
<span matRipple class="mat-mdc-button-ripple"
1010
[matRippleAnimation]="_rippleAnimation"
1111
[matRippleDisabled]="_isRippleDisabled()"
1212
[matRippleCentered]="_isRippleCentered"

src/material-experimental/mdc-button/button.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '@material/button/mixins';
2+
@import '@material/button/variables';
23
@import '@material/ripple/mixins';
34
@import '../mdc-helpers/mdc-helpers';
45
@import '../../cdk/a11y/a11y';
@@ -17,4 +18,20 @@
1718

1819
@include _mat-button-interactive();
1920
@include _mat-button-disabled();
21+
@include _mat-button-ripple-position();
22+
23+
}
24+
25+
// Since the stroked button has has an actual border that reduces the available space for
26+
// child elements such as the ripple container or focus overlay, an inherited border radius
27+
// for the absolute-positioned child elements does not work properly. This is because the
28+
// child element cannot expand to the same boundaries as the parent element with a border.
29+
// In order to work around this issue by *not* hiding overflow, we adjust the child elements
30+
// to fully cover the actual button element. This means that the border-radius would be correct
31+
// then. See: https://github.com/angular/components/issues/13738
32+
.mat-mdc-outlined-button .mat-mdc-button-ripple {
33+
top: -$mdc-button-outlined-border-width;
34+
left: -$mdc-button-outlined-border-width;
35+
bottom: -$mdc-button-outlined-border-width;
36+
right: -$mdc-button-outlined-border-width;
2037
}

src/material-experimental/mdc-button/fab.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.mat-mdc-fab, .mat-mdc-mini-fab {
1010
@include _mat-button-interactive();
1111
@include _mat-button-disabled();
12+
@include _mat-button-ripple-position();
1213
}
1314

1415
.mat-mdc-fab, .mat-mdc-mini-fab {

src/material-experimental/mdc-button/icon-button.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
border-radius: 50%;
1414

1515
@include _mat-button-disabled();
16+
@include _mat-button-ripple-position();
1617
}

0 commit comments

Comments
 (0)