Skip to content

Commit 10affcf

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 afb0ee3 commit 10affcf

File tree

10 files changed

+32
-13
lines changed

10 files changed

+32
-13
lines changed

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

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

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

99101
// 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
@@ -75,8 +75,11 @@
7575
}
7676
}
7777

78-
// The ripple container should match the bounds of the entire button.
79-
.mat-button-ripple, .mat-button-focus-overlay {
78+
// The ripple container and focus overlay should match the bounds of the entire button.
79+
// Increase specificity for the ripple container because ripple styles are part of
80+
// the `mat-core` mixin and can potentially overwrite the absolute position of the container.
81+
.mat-button-ripple.mat-ripple,
82+
.mat-button-focus-overlay {
8083
@include mat-fill;
8184

8285
// 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
@@ -58,7 +58,9 @@
5858
text-overflow: ellipsis;
5959
}
6060

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

6466
// 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
@@ -74,7 +74,9 @@ button.mat-menu-item {
7474
width: 100%;
7575
}
7676

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

8082
// 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
@@ -52,7 +52,9 @@ $mat-step-header-icon-size: 16px !default;
5252
overflow: hidden;
5353
}
5454

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

src/material-examples/ripple-overview/ripple-overview-example.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
.example-ripple-container {
2-
/** Necessary until: https://github.com/angular/material2/pull/11913*/
3-
position: relative;
4-
52
cursor: pointer;
63
text-align: center;
74

0 commit comments

Comments
 (0)