Skip to content

Commit c9bd2ba

Browse files
devversionjelbourn
authored andcommitted
update(ripple): allow passing ripple config only (#9760)
Adds a method overload to the `launch` method of the `MatRipple` class. This should make it possible for developers to just pass in a configuration without coordinates that will be ignored (e.g. `launch(0, 0, {centered: true});`).
1 parent 1c15e8f commit c9bd2ba

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

src/lib/core/ripple/ripple.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MyComponent {
4646

4747
/** Shows a centered and persistent ripple. */
4848
launchRipple() {
49-
const rippleRef = this.ripple.launch(0, 0, {
49+
const rippleRef = this.ripple.launch({
5050
persistent: true,
5151
centered: true
5252
});
@@ -57,13 +57,21 @@ class MyComponent {
5757
}
5858
```
5959

60-
In the example above, the `x` and `y` parameters will be ignored, because the `centered`
61-
ripple option has been set to `true`.
60+
In the example above, no specific coordinates have been passed, because the `centered`
61+
ripple option has been set to `true` and the coordinates would not matter.
6262

6363
Ripples that are being dispatched programmatically can be launched with the `persistent` option.
6464
This means that the ripples will not fade out automatically, and need to be faded out using
6565
the `RippleRef` (*useful for focus indicators*).
6666

67+
In case, developers want to launch ripples at specific coordinates within the element, the
68+
`launch()` method also accepts `x` and `y` coordinates as parameters. Those coordinates
69+
are relative to the ripple container element.
70+
71+
```ts
72+
const rippleRef = this.ripple.launch(10, 10, {persistent: true});
73+
```
74+
6775
### Global options
6876

6977
Developers are able to specify options for all ripples inside of their application.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,24 @@ describe('MatRipple', () => {
390390

391391
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
392392
}));
393+
394+
it('should allow passing only a configuration', fakeAsync(() => {
395+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
396+
397+
const rippleRef = rippleDirective.launch({persistent: true});
398+
399+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
400+
401+
tick(enterDuration + exitDuration);
402+
403+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
404+
405+
rippleRef.fadeOut();
406+
407+
tick(exitDuration);
408+
409+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
410+
}));
393411
});
394412

395413
describe('global ripple options', () => {

src/lib/core/ripple/ripple.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
150150
this._rippleRenderer._removeTriggerEvents();
151151
}
152152

153-
/** Launches a manual ripple at the specified position. */
154-
launch(x: number, y: number, config?: RippleConfig): RippleRef {
155-
return this._rippleRenderer.fadeInRipple(x, y, {...this.rippleConfig, ...config});
156-
}
157-
158153
/** Fades out all currently showing ripple elements. */
159154
fadeOutAll() {
160155
this._rippleRenderer.fadeOutAll();
@@ -183,5 +178,28 @@ export class MatRipple implements OnInit, OnDestroy, RippleTarget {
183178
this._rippleRenderer.setupTriggerEvents(this.trigger);
184179
}
185180
}
181+
182+
/**
183+
* Launches a manual ripple using the specified ripple configuration.
184+
* @param config Configuration for the manual ripple.
185+
*/
186+
launch(config: RippleConfig): RippleRef;
187+
188+
/**
189+
* Launches a manual ripple at the specified coordinates within the element.
190+
* @param x Coordinate within the element, along the X axis at which to fade-in the ripple.
191+
* @param y Coordinate within the element, along the Y axis at which to fade-in the ripple.
192+
* @param config Optional ripple configuration for the manual ripple.
193+
*/
194+
launch(x: number, y: number, config?: RippleConfig): RippleRef;
195+
196+
/** Launches a manual ripple at the specified coordinated or just by the ripple config. */
197+
launch(configOrX: number | RippleConfig, y: number = 0, config?: RippleConfig): RippleRef {
198+
if (typeof configOrX === 'number') {
199+
return this._rippleRenderer.fadeInRipple(configOrX, y, {...this.rippleConfig, ...config});
200+
} else {
201+
return this._rippleRenderer.fadeInRipple(0, 0, {...this.rippleConfig, ...configOrX});
202+
}
203+
}
186204
}
187205

0 commit comments

Comments
 (0)