Skip to content

Commit cb0dcb5

Browse files
committed
fix: blurry ripples for slide-toggle, radio, checkbox in MS edge.
Fixes blurry ripples in the slide-toggle, radio and checkbox in Microsoft Edge. The ripples have been blurry because the `border-radius` in an absolute position seems to cause render problems for Edge. Since the ripples are circular by default, the `border-radius` can be removed and the ripple radius just needs to be set to the value that has been set through CSS before this change. This fixes the blurry ripples in MS Edge and might also improve rendering-stability of the ripples. Fixes #8392
1 parent 541a95e commit cb0dcb5

File tree

9 files changed

+37
-20
lines changed

9 files changed

+37
-20
lines changed

src/lib/checkbox/checkbox.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
<div matRipple class="mat-checkbox-ripple"
1919
[matRippleTrigger]="label"
2020
[matRippleDisabled]="_isRippleDisabled()"
21-
[matRippleCentered]="true"></div>
21+
[matRippleRadius]="_rippleConfig.radius"
22+
[matRippleSpeedFactor]="_rippleConfig.speedFactor"
23+
[matRippleCentered]="_rippleConfig.centered">
24+
</div>
2225
<div class="mat-checkbox-frame"></div>
2326
<div class="mat-checkbox-background">
2427
<svg version="1.1"

src/lib/checkbox/checkbox.scss

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $_mat-checkbox-mark-path-length: 22.910259;
99
$_mat-checkbox-indeterminate-checked-easing-function: cubic-bezier(0.14, 0, 0, 1);
1010

1111
// The ripple size of the checkbox
12-
$_mat-checkbox-ripple-size: 15px;
12+
$_mat-checkbox-ripple-radius: 25px;
1313

1414
// The amount of spacing between the checkbox and its label.
1515
$_mat-checkbox-item-spacing: $mat-toggle-padding;
@@ -413,11 +413,10 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
413413

414414
.mat-checkbox-ripple {
415415
position: absolute;
416-
left: -$_mat-checkbox-ripple-size;
417-
top: -$_mat-checkbox-ripple-size;
418-
right: -$_mat-checkbox-ripple-size;
419-
bottom: -$_mat-checkbox-ripple-size;
420-
border-radius: 50%;
416+
left: $mat-checkbox-size / 2 - $_mat-checkbox-ripple-radius;
417+
top: $mat-checkbox-size / 2 - $_mat-checkbox-ripple-radius;
418+
height: $_mat-checkbox-ripple-radius * 2;
419+
width: $_mat_checkbox-ripple-radius * 2;
421420
z-index: 1;
422421
pointer-events: none;
423422
}

src/lib/checkbox/checkbox.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
mixinDisabled,
3636
mixinDisableRipple,
3737
mixinTabIndex,
38+
RippleConfig,
3839
RippleRef,
3940
} from '@angular/material/core';
4041

@@ -178,6 +179,9 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
178179
/** Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor. */
179180
@ViewChild(MatRipple) _ripple: MatRipple;
180181

182+
/** Ripple configuration for the mouse ripples and focus indicators. */
183+
_rippleConfig: RippleConfig = {centered: true, radius: 25, speedFactor: 1.5};
184+
181185
/**
182186
* Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor.
183187
* @docs-private
@@ -336,7 +340,7 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
336340
/** Function is called whenever the focus changes for the input element. */
337341
private _onInputFocusChange(focusOrigin: FocusOrigin) {
338342
if (!this._focusRipple && focusOrigin === 'keyboard') {
339-
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, centered: true});
343+
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, ...this._rippleConfig});
340344
} else if (!focusOrigin) {
341345
this._removeFocusRipple();
342346
this.onTouched();

src/lib/radio/radio.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
<div mat-ripple class="mat-radio-ripple"
99
[matRippleTrigger]="label"
1010
[matRippleDisabled]="_isRippleDisabled()"
11-
[matRippleCentered]="true"></div>
11+
[matRippleCentered]="_rippleConfig.centered"
12+
[matRippleRadius]="_rippleConfig.radius"
13+
[matRippleSpeedFactor]="_rippleConfig.speedFactor">
14+
</div>
1215
</div>
1316

1417
<input #input class="mat-radio-input cdk-visually-hidden" type="radio"

src/lib/radio/radio.scss

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
$mat-radio-size: $mat-toggle-size !default;
6-
$mat-radio-ripple-size: $mat-radio-size * 0.75;
6+
$mat-radio-ripple-radius: 25px;
77

88
// Top-level host container.
99
.mat-radio-button {
@@ -101,11 +101,10 @@ $mat-radio-ripple-size: $mat-radio-size * 0.75;
101101

102102
.mat-radio-ripple {
103103
position: absolute;
104-
left: -$mat-radio-ripple-size;
105-
top: -$mat-radio-ripple-size;
106-
right: -$mat-radio-ripple-size;
107-
bottom: -$mat-radio-ripple-size;
108-
border-radius: 50%;
104+
left: $mat-radio-size / 2 - $mat-radio-ripple-radius;
105+
top: $mat-radio-size / 2 - $mat-radio-ripple-radius;
106+
height: $mat-radio-ripple-radius * 2;
107+
width: $mat-radio-ripple-radius * 2;
109108
z-index: 1;
110109
pointer-events: none;
111110
}

src/lib/radio/radio.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
mixinColor,
4040
mixinDisabled,
4141
mixinDisableRipple,
42+
RippleConfig,
4243
RippleRef,
4344
} from '@angular/material/core';
4445

@@ -483,6 +484,9 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
483484
/** The child ripple instance. */
484485
@ViewChild(MatRipple) _ripple: MatRipple;
485486

487+
/** Ripple configuration for the mouse ripples and focus indicators. */
488+
_rippleConfig: RippleConfig = {centered: true, radius: 23, speedFactor: 1.5};
489+
486490
/** Reference to the current focus ripple. */
487491
private _focusRipple: RippleRef | null;
488492

@@ -596,7 +600,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
596600
/** Function is called whenever the focus changes for the input element. */
597601
private _onInputFocusChange(focusOrigin: FocusOrigin) {
598602
if (!this._focusRipple && focusOrigin === 'keyboard') {
599-
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, centered: true});
603+
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, ...this._rippleConfig});
600604
} else if (!focusOrigin) {
601605
if (this.radioGroup) {
602606
this.radioGroup._touch();

src/lib/slide-toggle/slide-toggle.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
<div class="mat-slide-toggle-ripple" mat-ripple
2626
[matRippleTrigger]="label"
27-
[matRippleCentered]="true"
28-
[matRippleDisabled]="disableRipple || disabled">
27+
[matRippleDisabled]="disableRipple || disabled"
28+
[matRippleCentered]="_rippleConfig.centered"
29+
[matRippleRadius]="_rippleConfig.radius"
30+
[matRippleSpeedFactor]="_rippleConfig.speedFactor">
2931
</div>
3032

3133
</div>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
160160
left: $mat-slide-toggle-thumb-size / 2 - $mat-slide-toggle-ripple-radius;
161161
height: $mat-slide-toggle-ripple-radius * 2;
162162
width: $mat-slide-toggle-ripple-radius * 2;
163-
border-radius: 50%;
164163
z-index: 1;
165164
pointer-events: none;
166165
}

src/lib/slide-toggle/slide-toggle.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
mixinDisabled,
3939
mixinDisableRipple,
4040
mixinTabIndex,
41+
RippleConfig,
4142
RippleRef,
4243
} from '@angular/material/core';
4344

@@ -139,6 +140,9 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
139140
/** Reference to the ripple directive on the thumb container. */
140141
@ViewChild(MatRipple) _ripple: MatRipple;
141142

143+
/** Ripple configuration for the mouse ripples and focus indicators. */
144+
_rippleConfig: RippleConfig = {centered: true, radius: 23, speedFactor: 1.5};
145+
142146
constructor(elementRef: ElementRef,
143147
renderer: Renderer2,
144148
private _platform: Platform,
@@ -232,7 +236,7 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
232236
private _onInputFocusChange(focusOrigin: FocusOrigin) {
233237
if (!this._focusRipple && focusOrigin === 'keyboard') {
234238
// For keyboard focus show a persistent ripple as focus indicator.
235-
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, centered: true});
239+
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, ...this._rippleConfig});
236240
} else if (!focusOrigin) {
237241
this.onTouched();
238242

0 commit comments

Comments
 (0)