Skip to content

Commit a6c91bc

Browse files
devversionmmalerba
authored andcommitted
update(ripple): remove deprecated speed factor option (#12258)
* update(ripple): remove deprecated speed factor option. * Removes the deprecated `[matRippleSpeedFactor]` and global `baseSpeedFactor` option. * Adds update rules that can automatically switch to the new API (as much as possible) and even calculate the new durations based on the previously specified speed factor. BREAKING CHANGE: deprecated `[matRippleSpeedFactor]` and `baseSpeedFactor` for the ripples have been removed. Use the new animation config instead. * Add test case; fix NodeJS version target circular dependency; Support for rule version constraints
1 parent e4c6cc9 commit a6c91bc

25 files changed

+385
-96
lines changed

src/lib/chips/chip.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
234234
this._chipRipple.setupTriggerEvents(_elementRef.nativeElement);
235235

236236
if (globalOptions) {
237+
// TODO(paul): Do not copy each option manually. Allow dynamic global option changes: #9729
237238
this._ripplesGloballyDisabled = !!globalOptions.disabled;
238-
// TODO(paul): Once the speedFactor is removed, we no longer need to copy each single option.
239239
this.rippleConfig = {
240-
speedFactor: globalOptions.baseSpeedFactor,
241240
animation: globalOptions.animation,
242241
terminateOnPointerUp: globalOptions.terminateOnPointerUp,
243242
};

src/lib/core/ripple/ripple-renderer.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ export type RippleConfig = {
1717
persistent?: boolean;
1818
animation?: RippleAnimationConfig;
1919
terminateOnPointerUp?: boolean;
20-
/**
21-
* @deprecated Use the `animation` property instead.
22-
* @breaking-change 7.0.0
23-
*/
24-
speedFactor?: number;
2520
};
2621

2722
/**
@@ -140,7 +135,7 @@ export class RippleRenderer {
140135
const radius = config.radius || distanceToFurthestCorner(x, y, containerRect);
141136
const offsetX = x - containerRect.left;
142137
const offsetY = y - containerRect.top;
143-
const duration = animationConfig.enterDuration / (config.speedFactor || 1);
138+
const duration = animationConfig.enterDuration;
144139

145140
const ripple = document.createElement('div');
146141
ripple.classList.add('mat-ripple-element');

src/lib/core/ripple/ripple.spec.ts

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('MatRipple', () => {
6262
fixture = TestBed.createComponent(BasicRippleContainer);
6363
fixture.detectChanges();
6464

65-
rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
65+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
6666
rippleDirective = fixture.componentInstance.ripple;
6767
});
6868

@@ -262,7 +262,7 @@ describe('MatRipple', () => {
262262
fixture = TestBed.createComponent(RippleContainerWithNgIf);
263263
fixture.detectChanges();
264264

265-
rippleTarget = fixture.debugElement.nativeElement.querySelector('[mat-ripple]');
265+
rippleTarget = fixture.debugElement.nativeElement.querySelector('.mat-ripple');
266266

267267
fixture.componentInstance.isDestroyed = true;
268268
fixture.detectChanges();
@@ -377,7 +377,7 @@ describe('MatRipple', () => {
377377
fixture = TestBed.createComponent(BasicRippleContainer);
378378
fixture.detectChanges();
379379

380-
rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
380+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
381381
rippleDirective = fixture.componentInstance.ripple;
382382
});
383383

@@ -492,7 +492,7 @@ describe('MatRipple', () => {
492492
fixture = TestBed.createComponent(testComponent);
493493
fixture.detectChanges();
494494

495-
rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
495+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
496496
rippleDirective = fixture.componentInstance.ripple;
497497
}
498498

@@ -534,41 +534,6 @@ describe('MatRipple', () => {
534534
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
535535
});
536536

537-
it('should support changing the baseSpeedFactor', fakeAsync(() => {
538-
createTestComponent({ baseSpeedFactor: 0.5 });
539-
540-
dispatchMouseEvent(rippleTarget, 'mousedown');
541-
dispatchMouseEvent(rippleTarget, 'mouseup');
542-
543-
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
544-
545-
// Calculates the speedFactor for the duration. Those factors needs to be inverted, because
546-
// a lower speed factor, will make the duration longer. For example: 0.5 => 2x duration.
547-
let fadeInFactor = 1 / 0.5;
548-
549-
// Calculates the duration for fading-in and fading-out the ripple.
550-
tick(enterDuration * fadeInFactor + exitDuration);
551-
552-
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
553-
}));
554-
555-
it('should combine individual speed factor with baseSpeedFactor', fakeAsync(() => {
556-
createTestComponent({ baseSpeedFactor: 0.5 });
557-
558-
rippleDirective.launch(0, 0, { speedFactor: 1.5 });
559-
560-
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
561-
562-
// Calculates the speedFactor for the duration. Those factors needs to be inverted, because
563-
// a lower speed factor, will make the duration longer. For example: 0.5 => 2x duration.
564-
let fadeInFactor = 1 / (0.5 * 1.5);
565-
566-
// Calculates the duration for fading-in and fading-out the ripple.
567-
tick(enterDuration * fadeInFactor + exitDuration);
568-
569-
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
570-
}));
571-
572537
it('should support changing the animation duration', fakeAsync(() => {
573538
createTestComponent({
574539
animation: {enterDuration: 100, exitDuration: 100}
@@ -619,7 +584,7 @@ describe('MatRipple', () => {
619584
fixture = TestBed.createComponent(BasicRippleContainer);
620585
fixture.detectChanges();
621586

622-
rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
587+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
623588
rippleDirective = fixture.componentInstance.ripple;
624589
});
625590

@@ -637,7 +602,7 @@ describe('MatRipple', () => {
637602
fixture.detectChanges();
638603

639604
controller = fixture.debugElement.componentInstance;
640-
rippleTarget = fixture.debugElement.nativeElement.querySelector('[mat-ripple]');
605+
rippleTarget = fixture.debugElement.nativeElement.querySelector('.mat-ripple');
641606
});
642607

643608
it('sets ripple color', () => {
@@ -757,7 +722,7 @@ describe('MatRipple', () => {
757722

758723
@Component({
759724
template: `
760-
<div id="container" #ripple="matRipple" mat-ripple [matRippleSpeedFactor]="0"
725+
<div id="container" #ripple="matRipple" matRipple
761726
style="position: relative; width:300px; height:200px;">
762727
</div>
763728
`,
@@ -769,8 +734,7 @@ class BasicRippleContainer {
769734
@Component({
770735
template: `
771736
<div id="container" style="position: relative; width:300px; height:200px;"
772-
mat-ripple
773-
[matRippleSpeedFactor]="0"
737+
matRipple
774738
[matRippleTrigger]="trigger"
775739
[matRippleCentered]="centered"
776740
[matRippleRadius]="radius"
@@ -792,11 +756,11 @@ class RippleContainerWithInputBindings {
792756
}
793757

794758
@Component({
795-
template: `<div id="container" #ripple="matRipple" mat-ripple></div>`,
759+
template: `<div id="container" #ripple="matRipple" matRipple></div>`,
796760
})
797761
class RippleContainerWithoutBindings {}
798762

799-
@Component({ template: `<div id="container" mat-ripple [matRippleSpeedFactor]="0"
763+
@Component({ template: `<div id="container" matRipple
800764
*ngIf="!isDestroyed"></div>` })
801765
class RippleContainerWithNgIf {
802766
@ViewChild(MatRipple) ripple: MatRipple;

src/lib/core/ripple/ripple.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ export interface RippleGlobalOptions {
3737
*/
3838
animation?: RippleAnimationConfig;
3939

40-
/**
41-
* If set, the default duration of the fade-in animation is divided by this value. For example,
42-
* setting it to 0.5 will cause the ripple fade-in animation to take twice as long.
43-
* A changed speedFactor will not affect the fade-out duration of the ripples.
44-
* @deprecated Use the `animation` global option instead.
45-
* @breaking-change 7.0.0
46-
*/
47-
baseSpeedFactor?: number;
48-
4940
/**
5041
* Whether ripples should start fading out immediately after the mouse our touch is released. By
5142
* default, ripples will wait for the enter animation to complete and for mouse or touch release.
@@ -86,15 +77,6 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
8677
*/
8778
@Input('matRippleRadius') radius: number = 0;
8879

89-
/**
90-
* If set, the normal duration of ripple animations is divided by this value. For example,
91-
* setting it to 0.5 will cause the animations to take twice as long.
92-
* A changed speedFactor will not modify the fade-out duration of the ripples.
93-
* @deprecated Use the [matRippleAnimation] binding instead.
94-
* @breaking-change 7.0.0
95-
*/
96-
@Input('matRippleSpeedFactor') speedFactor: number = 1;
97-
9880
/**
9981
* Configuration for the ripple animation. Allows modifying the enter and exit animation
10082
* duration of the ripples. The animation durations will be overwritten if the
@@ -174,7 +156,6 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
174156
color: this.color,
175157
animation: {...this._globalOptions.animation, ...this.animation},
176158
terminateOnPointerUp: this._globalOptions.terminateOnPointerUp,
177-
speedFactor: this.speedFactor * (this._globalOptions.baseSpeedFactor || 1),
178159
};
179160
}
180161

src/lib/schematics/update/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
*/
88

99
import {Rule} from '@angular-devkit/schematics';
10+
import {TargetVersion} from './target-version';
1011
import {createUpdateRule} from './update';
1112

12-
/** Possible versions that can be automatically migrated by `ng update`. */
13-
export enum TargetVersion {
14-
V6,
15-
V7,
16-
}
17-
1813
/** Entry point for the migration schematics with target of Angular Material 6.0.0 */
1914
export function updateToV6(): Rule {
2015
return createUpdateRule(TargetVersion.V6);

src/lib/schematics/update/material/data/attribute-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {TargetVersion} from '../../target-version';
910
import {VersionChanges} from '../transform-change-data';
10-
import {TargetVersion} from '../../index';
1111

1212
export interface MaterialAttributeSelectorData {
1313
/** The attribute name to replace. */

src/lib/schematics/update/material/data/class-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialClassNameData {

src/lib/schematics/update/material/data/constructor-checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
/**

src/lib/schematics/update/material/data/css-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialCssSelectorData {

src/lib/schematics/update/material/data/element-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialElementSelectorData {

src/lib/schematics/update/material/data/input-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialInputNameData {

src/lib/schematics/update/material/data/method-call-checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialMethodCallData {

src/lib/schematics/update/material/data/output-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialOutputNameData {

src/lib/schematics/update/material/data/property-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialPropertyNameData {

src/lib/schematics/update/material/transform-change-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {TargetVersion} from '../index';
8+
9+
import {TargetVersion} from '../target-version';
910

1011
export type VersionChanges<T> = {
1112
[target in TargetVersion]?: ReadableChange<T>[];
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/** Converts the specified speed factor into the exact static enter duration. */
10+
export function convertSpeedFactorToDuration(factor: number) {
11+
// Based on the numeric speed factor value that only affected the `enterDuration` we can
12+
// now calculate the exact `enterDuration`. 450ms is the enter duration without factor.
13+
return 450 / (factor || 1);
14+
}
15+
16+
/**
17+
* Creates a runtime TypeScript expression that can be used in order to calculate the duration
18+
* from the speed factor expression that couldn't be statically analyzed.
19+
*
20+
* @param speedFactorValue Speed factor expression that couldn't be statically analyzed.
21+
*/
22+
export function createSpeedFactorConvertExpression(speedFactorValue: string): string {
23+
// To be sure that the speed factor value expression is calculated properly, we need to add
24+
// the according parenthesis.
25+
return `450 / (${speedFactorValue})`;
26+
}

0 commit comments

Comments
 (0)