Skip to content

Commit 8b7a3af

Browse files
devversiontinayuangao
authored andcommitted
fix: blurry ripples for slide-toggle, radio, checkbox in MS edge. (#8514)
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 8205cb2 commit 8b7a3af

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
@@ -19,7 +19,10 @@
1919
<div matRipple class="mat-checkbox-ripple"
2020
[matRippleTrigger]="label"
2121
[matRippleDisabled]="_isRippleDisabled()"
22-
[matRippleCentered]="true"></div>
22+
[matRippleRadius]="_rippleConfig.radius"
23+
[matRippleSpeedFactor]="_rippleConfig.speedFactor"
24+
[matRippleCentered]="_rippleConfig.centered">
25+
</div>
2326
<div class="mat-checkbox-frame"></div>
2427
<div class="mat-checkbox-background">
2528
<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
@@ -34,6 +34,7 @@ import {
3434
mixinDisabled,
3535
mixinDisableRipple,
3636
mixinTabIndex,
37+
RippleConfig,
3738
RippleRef,
3839
} from '@angular/material/core';
3940

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

181+
/** Ripple configuration for the mouse ripples and focus indicators. */
182+
_rippleConfig: RippleConfig = {centered: true, radius: 25, speedFactor: 1.5};
183+
180184
/**
181185
* Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor.
182186
* @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
@@ -38,6 +38,7 @@ import {
3838
mixinColor,
3939
mixinDisabled,
4040
mixinDisableRipple,
41+
RippleConfig,
4142
RippleRef,
4243
} from '@angular/material/core';
4344

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

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

@@ -595,7 +599,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
595599
/** Function is called whenever the focus changes for the input element. */
596600
private _onInputFocusChange(focusOrigin: FocusOrigin) {
597601
if (!this._focusRipple && focusOrigin === 'keyboard') {
598-
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, centered: true});
602+
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, ...this._rippleConfig});
599603
} else if (!focusOrigin) {
600604
if (this.radioGroup) {
601605
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
@@ -161,7 +161,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
161161
left: $mat-slide-toggle-thumb-size / 2 - $mat-slide-toggle-ripple-radius;
162162
height: $mat-slide-toggle-ripple-radius * 2;
163163
width: $mat-slide-toggle-ripple-radius * 2;
164-
border-radius: 50%;
165164
z-index: 1;
166165
pointer-events: none;
167166
}

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

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

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

142+
/** Ripple configuration for the mouse ripples and focus indicators. */
143+
_rippleConfig: RippleConfig = {centered: true, radius: 23, speedFactor: 1.5};
144+
141145
constructor(elementRef: ElementRef,
142146
private _platform: Platform,
143147
private _focusMonitor: FocusMonitor,
@@ -230,7 +234,7 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
230234
private _onInputFocusChange(focusOrigin: FocusOrigin) {
231235
if (!this._focusRipple && focusOrigin === 'keyboard') {
232236
// For keyboard focus show a persistent ripple as focus indicator.
233-
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, centered: true});
237+
this._focusRipple = this._ripple.launch(0, 0, {persistent: true, ...this._rippleConfig});
234238
} else if (!focusOrigin) {
235239
this.onTouched();
236240

0 commit comments

Comments
 (0)