Skip to content

Commit 2658d9d

Browse files
crisbetojelbourn
authored andcommitted
fix(material-experimental/mdc-radio): use consistent ripple timings (#18590)
- Switches the MDC-based radio button to use the ripple timings from MDC, rather than a hardcoded one. - Reworks the rest of the MDC-based components so that they don't re-create the ripple config object for each instance. It's not a huge improvement, there's no need for it to consume extra memory. (cherry picked from commit 76846b8)
1 parent 52b2b62 commit 2658d9d

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

src/material-experimental/mdc-button/button-base.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export const MAT_BUTTON_HOST = {
3838
'class': 'mat-mdc-focus-indicator',
3939
};
4040

41+
/** Configuration for the ripple animation. */
42+
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
43+
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
44+
exitDuration: numbers.FG_DEACTIVATION_MS
45+
};
46+
4147
/** List of classes to add to buttons instances based on host attribute selector. */
4248
const HOST_SELECTOR_MDC_CLASS_PAIR: {selector: string, mdcClasses: string[]}[] = [
4349
{
@@ -84,10 +90,7 @@ export const _MatButtonBaseMixin: CanDisableRippleCtor&CanDisableCtor&CanColorCt
8490
export class MatButtonBase extends _MatButtonBaseMixin implements CanDisable, CanColor,
8591
CanDisableRipple {
8692
/** The ripple animation configuration to use for the buttons. */
87-
_rippleAnimation: RippleAnimationConfig = {
88-
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
89-
exitDuration: numbers.FG_DEACTIVATION_MS
90-
};
93+
_rippleAnimation: RippleAnimationConfig = RIPPLE_ANIMATION_CONFIG;
9194

9295
/** Whether the ripple is centered on the button. */
9396
_isRippleCentered = false;

src/material-experimental/mdc-checkbox/checkbox.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
MAT_CHECKBOX_DEFAULT_OPTIONS,
3232
MatCheckboxClickAction, MatCheckboxDefaultOptions
3333
} from '@angular/material/checkbox';
34-
import {ThemePalette} from '@angular/material/core';
34+
import {ThemePalette, RippleAnimationConfig} from '@angular/material/core';
3535
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3636
import {MDCCheckboxAdapter, MDCCheckboxFoundation} from '@material/checkbox';
3737
import {numbers} from '@material/ripple';
@@ -52,6 +52,12 @@ export class MatCheckboxChange {
5252
checked: boolean;
5353
}
5454

55+
/** Configuration for the ripple animation. */
56+
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
57+
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
58+
exitDuration: numbers.FG_DEACTIVATION_MS,
59+
};
60+
5561
@Component({
5662
selector: 'mat-checkbox',
5763
templateUrl: 'checkbox.html',
@@ -185,10 +191,7 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess
185191
_classes: {[key: string]: boolean} = {'mdc-checkbox__native-control': true};
186192

187193
/** Animation config for the ripple. */
188-
_rippleAnimation = {
189-
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
190-
exitDuration: numbers.FG_DEACTIVATION_MS,
191-
};
194+
_rippleAnimation = RIPPLE_ANIMATION_CONFIG;
192195

193196
/** ControlValueAccessor onChange */
194197
private _cvaOnChange = (_: boolean) => {};

src/material-experimental/mdc-chips/chip.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export interface MatChipEvent {
5858
chip: MatChip;
5959
}
6060

61+
/** Configuration for the ripple animation. */
62+
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
63+
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
64+
exitDuration: numbers.FG_DEACTIVATION_MS
65+
};
66+
6167
/**
6268
* Directive to add MDC CSS to non-basic chips.
6369
* @docs-private
@@ -114,10 +120,7 @@ const _MatChipMixinBase:
114120
export class MatChip extends _MatChipMixinBase implements AfterContentInit, AfterViewInit,
115121
CanColor, CanDisableRipple, HasTabIndex, OnDestroy {
116122
/** The ripple animation configuration to use for the chip. */
117-
readonly _rippleAnimation: RippleAnimationConfig = {
118-
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
119-
exitDuration: numbers.FG_DEACTIVATION_MS
120-
};
123+
readonly _rippleAnimation: RippleAnimationConfig = RIPPLE_ANIMATION_CONFIG;
121124

122125
/** Whether the ripple is centered on the chip. */
123126
readonly _isRippleCentered = false;

src/material-experimental/mdc-radio/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ng_module(
2525
"//src/material/radio",
2626
"@npm//@angular/forms",
2727
"@npm//@material/radio",
28+
"@npm//@material/ripple",
2829
],
2930
)
3031

@@ -71,6 +72,7 @@ ng_test_library(
7172
ng_web_test_suite(
7273
name = "unit_tests",
7374
static_files = [
75+
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
7476
"@npm//:node_modules/@material/radio/dist/mdc.radio.js",
7577
],
7678
deps = [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
[matRippleDisabled]="_isRippleDisabled()"
2525
[matRippleCentered]="true"
2626
[matRippleRadius]="20"
27-
[matRippleAnimation]="{enterDuration: 150}">
27+
[matRippleAnimation]="_rippleAnimation">
2828
<div class="mat-ripple-element mat-radio-persistent-ripple"></div>
2929
</div>
3030
</div>

src/material-experimental/mdc-radio/radio.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {FocusMonitor} from '@angular/cdk/a11y';
3232
import {UniqueSelectionDispatcher} from '@angular/cdk/collections';
3333
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3434
import {NG_VALUE_ACCESSOR} from '@angular/forms';
35+
import {RippleAnimationConfig} from '@angular/material/core';
36+
import {numbers} from '@material/ripple';
3537

3638
// Re-export symbols used by the base Material radio component so that users do not need to depend
3739
// on both packages.
@@ -48,6 +50,11 @@ export const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any = {
4850
multi: true
4951
};
5052

53+
/** Configuration for the ripple animation. */
54+
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
55+
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
56+
exitDuration: numbers.FG_DEACTIVATION_MS
57+
};
5158

5259
/**
5360
* A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
@@ -108,6 +115,9 @@ export class MatRadioButton extends BaseMatRadioButton implements AfterViewInit,
108115
},
109116
};
110117

118+
/** Configuration for the underlying ripple. */
119+
_rippleAnimation: RippleAnimationConfig = RIPPLE_ANIMATION_CONFIG;
120+
111121
_radioFoundation = new MDCRadioFoundation(this._radioAdapter);
112122
_classes: {[key: string]: boolean} = {};
113123

src/material-experimental/mdc-slide-toggle/slide-toggle.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ import {
4242
// Increasing integer for generating unique ids for slide-toggle components.
4343
let nextUniqueId = 0;
4444

45+
/** Configuration for the ripple animation. */
46+
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
47+
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
48+
exitDuration: numbers.FG_DEACTIVATION_MS,
49+
};
50+
4551
/** @docs-private */
4652
export const MAT_SLIDE_TOGGLE_VALUE_ACCESSOR: any = {
4753
provide: NG_VALUE_ACCESSOR,
@@ -104,10 +110,7 @@ export class MatSlideToggle implements ControlValueAccessor, AfterViewInit, OnDe
104110
_focused: boolean;
105111

106112
/** Configuration for the underlying ripple. */
107-
_rippleAnimation: RippleAnimationConfig = {
108-
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
109-
exitDuration: numbers.FG_DEACTIVATION_MS,
110-
};
113+
_rippleAnimation: RippleAnimationConfig = RIPPLE_ANIMATION_CONFIG;
111114

112115
/** The color palette for this slide toggle. */
113116
@Input() color: ThemePalette = 'accent';

0 commit comments

Comments
 (0)