Skip to content

Commit c5ca1cd

Browse files
committed
feat(ripple): no longer require additional setup when using MatRipple directive
Currently if a developer wants to use the `matRipple` directive, he needs to set the position of the element to either `absolute` or `relative`. This makes the `matRipple` directive kind of not intuitive. Developers should be just able to place the `matRipple` directive, and everything works. Developers should not ask themselves at some point: _Why do my ripples don't display at all? ... Ahh I need to apply `position: relative` to the host element_ ```html <button matRipple>Button with ripple</button> <mat-toolbar matRipple>Toolbar with ripple</button> <mat-card matRipple>Card with ripple</mat-card> ```
1 parent d96adbe commit c5ca1cd

File tree

11 files changed

+46
-12
lines changed

11 files changed

+46
-12
lines changed

src/demo-app/ripple/ripple-demo.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,18 @@
5656
Click me
5757
</div>
5858
</section>
59+
60+
<h3>MatRipple without options</h3>
61+
62+
<p>
63+
<mat-card matRipple>Just a normal card.</mat-card>
64+
</p>
65+
66+
<p>
67+
<mat-toolbar matRipple>Just a normal toolbar</mat-toolbar>
68+
</p>
69+
70+
<p>
71+
<button matRipple>Just a normal button</button>
72+
</p>
5973
</div>

src/demo-app/ripple/ripple-demo.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
font-size: 24px;
1313
height: 150px;
1414
line-height: 150px;
15-
position: relative;
1615
text-align: center;
1716
transition: all 200ms linear;
1817
width: 200px;
@@ -27,7 +26,6 @@
2726

2827
&.demo-ripple-rounded {
2928
border-radius: 50%;
30-
overflow: hidden;
3129
// z-index needed to make clipping to border-radius work correctly.
3230
// http://stackoverflow.com/questions/20001515/
3331
z-index: 1;

src/lib/button-toggle/button-toggle.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ $mat-button-toggle-border-radius: 2px !default;
9292
}
9393
}
9494

95-
.mat-button-toggle-ripple {
95+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
96+
// potentially overwrite the absolute position of the container.
97+
.mat-button-toggle .mat-button-toggle-ripple {
9698
@include mat-fill;
9799

98100
// Disable pointer events for the ripple container, because the container will overlay the user

src/lib/button/button.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@
6565
}
6666
}
6767

68-
// The ripple container should match the bounds of the entire button.
69-
.mat-button-ripple, .mat-button-focus-overlay {
68+
// The ripple container and focus overlay should match the bounds of the entire button.
69+
// Increase specificity for the ripple container because ripple styles are part of
70+
// the `mat-core` mixin and can potentially overwrite the absolute position of the container.
71+
.mat-button-ripple.mat-ripple,
72+
.mat-button-focus-overlay {
7073
@include mat-fill;
7174

7275
// Disable pointer events for the ripple container and focus overlay because the container

src/lib/checkbox/checkbox.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
431431
left: 50%;
432432
}
433433

434-
.mat-checkbox-ripple {
434+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
435+
// potentially overwrite the absolute position of the container.
436+
.mat-checkbox .mat-checkbox-ripple {
435437
position: absolute;
436438
left: calc(50% - #{$_mat-checkbox-ripple-radius});
437439
top: calc(50% - #{$_mat-checkbox-ripple-radius});

src/lib/core/option/option.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
text-overflow: ellipsis;
5858
}
5959

60-
.mat-option-ripple {
60+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
61+
// potentially overwrite the absolute position of the container.
62+
.mat-option .mat-option-ripple {
6163
@include mat-fill;
6264

6365
// Disable pointer events for the ripple container because the container will overlay the

src/lib/core/ripple/_ripple.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
$mat-ripple-color-opacity: 0.1;
55

66
@mixin mat-ripple() {
7+
78
// The host element of an mat-ripple directive should always have a position of "absolute" or
8-
// "relative" so that the ripple divs it creates inside itself are correctly positioned.
9+
// "relative" so that the ripples inside are correctly positioned relatively to the container.
910
.mat-ripple {
1011
overflow: hidden;
1112

13+
// By default, every ripple container should have position: relative in favor of creating an
14+
// easy API for developers using the MatRipple directive.
15+
position: relative;
16+
1217
// In high contrast mode the ripple is opaque, causing it to obstruct the content.
1318
@include cdk-high-contrast {
1419
display: none;

src/lib/menu/menu.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ button.mat-menu-item {
7575
width: 100%;
7676
}
7777

78-
.mat-menu-ripple {
78+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
79+
// potentially overwrite the absolute position of the container.
80+
.mat-menu-item .mat-menu-ripple {
7981
@include mat-fill;
8082

8183
// Prevent any pointer events on the ripple container for a menu item. The ripple container is

src/lib/radio/radio.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ $mat-radio-ripple-radius: 25px;
115115
cursor: default;
116116
}
117117

118-
.mat-radio-ripple {
118+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
119+
// potentially overwrite the absolute position of the container.
120+
.mat-radio-button .mat-radio-ripple {
119121
position: absolute;
120122
left: calc(50% - #{$mat-radio-ripple-radius});
121123
top: calc(50% - #{$mat-radio-ripple-radius});

src/lib/slide-toggle/slide-toggle.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
172172
}
173173

174174
// Ripple positioning for the slide-toggle. Moves the ripple container into the center of the thumb.
175-
.mat-slide-toggle-ripple {
175+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
176+
// potentially overwrite the absolute position of the container.
177+
.mat-slide-toggle .mat-slide-toggle-ripple {
176178
position: absolute;
177179
top: calc(50% - #{$mat-slide-toggle-ripple-radius});
178180
left: calc(50% - #{$mat-slide-toggle-ripple-radius});

src/lib/stepper/step-header.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ $mat-step-header-icon-size: 16px !default;
5151
overflow: hidden;
5252
}
5353

54-
.mat-step-header-ripple {
54+
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
55+
// potentially overwrite the absolute position of the container.
56+
.mat-step-header .mat-step-header-ripple {
5557
@include mat-fill;
5658
pointer-events: none;
5759
}

0 commit comments

Comments
 (0)