Skip to content

Commit c707007

Browse files
devversionmmalerba
authored andcommitted
docs(ripple): update documentation (#7941)
* docs(ripple): update documentation * Improves the documentation of the `matRipple` attribute directive. References #7543. * Address feedback * Omit matRipple header
1 parent f6a9b1a commit c707007

File tree

2 files changed

+93
-48
lines changed

2 files changed

+93
-48
lines changed

src/lib/core/ripple/README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/lib/core/ripple/ripple.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Connect user input to screen reactions by using ripples to both indicate the point of touch, and to
2+
confirm that touch input was received. For touch or mouse, this occurs at the point of contact.
3+
4+
The `matRipple` attribute directive defines an area in which a ripple animates on user interaction.
5+
6+
```html
7+
<div matRipple [matRippleColor]="myColor">
8+
<ng-content></ng-content>
9+
</div>
10+
```
11+
12+
By default, a ripple is activated when the host element of the `matRipple` directive receives
13+
mouse or touch events. Upon being pressed, a ripple will begin fading in from the point of contact,
14+
radiating to cover the host element. Each ripple will fade out only upon release of the mouse or touch.
15+
16+
Ripples can also be triggered programmatically by getting a reference to the MatRipple directive
17+
and calling its `launch` method.
18+
19+
20+
### Ripple trigger
21+
22+
By default ripples will fade in on interaction with the directive's host element.
23+
In some situations, developers may want to show ripples on interaction with *some other* element,
24+
but still want to have the ripples placed in another location. This can be done by specifying
25+
the `matRippleTrigger` option that expects a reference to an `HTMLElement`.
26+
27+
```html
28+
<div>
29+
<div matRipple [matRippleTrigger]="trigger" class="my-ripple-container">
30+
<!-- This is the ripple container, but not the trigger element for ripples. -->
31+
</div>
32+
33+
<div #trigger></div>
34+
</div>
35+
```
36+
37+
### Manual ripples
38+
39+
Ripples can be shown programmatically by getting a reference to the `MatRipple` directive.
40+
41+
```ts
42+
class MyComponent {
43+
44+
/** Reference to the directive instance of the ripple. */
45+
@ViewChild(MatRipple) ripple: MatRipple;
46+
47+
/** Shows a centered and persistent ripple. */
48+
launchRipple() {
49+
const rippleRef = this.ripple.launch(0, 0, {
50+
persistent: true,
51+
centered: true
52+
});
53+
54+
// Fade out the ripple later.
55+
rippleRef.fadeOut();
56+
}
57+
}
58+
```
59+
60+
In the example above, the `x` and `y` parameters will be ignored, because the `centered`
61+
ripple option has been set to `true`.
62+
63+
Ripples that are being dispatched programmatically can be launched with the `persistent` option.
64+
This means that the ripples will not fade out automatically, and need to be faded out using
65+
the `RippleRef` (*useful for focus indicators*).
66+
67+
### Global options
68+
69+
Developers are able to specify options for all ripples inside of their application.
70+
71+
The speed of the ripples can be adjusted and the ripples can be disabled globally as well.
72+
73+
Global ripple options can be specified by setting the `MAT_RIPPLE_GLOBAL_OPTIONS` provider.
74+
75+
```ts
76+
const globalRippleConfig: RippleGlobalOptions = {
77+
disabled: true,
78+
baseSpeedFactor: 1.5 // Ripples will animate 50% faster than before.
79+
}
80+
81+
@NgModule({
82+
providers: [
83+
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useValue: globalRippleConfig}
84+
]
85+
})
86+
```
87+
88+
All currently available global options are shown here:
89+
90+
| Name | Type | Description |
91+
| --------------- | ------- | ----------------------------------------- |
92+
| disabled | boolean | Whether ripples should show or not. |
93+
| baseSpeedFactor | number | Factor to adjust ripple speed. |

0 commit comments

Comments
 (0)