Skip to content

Commit 83ca9a8

Browse files
andrewseguinjelbourn
authored andcommitted
docs(tooltip): minor improvements; more examples (#9544)
1 parent dcad946 commit 83ca9a8

11 files changed

+114
-8
lines changed

src/lib/tooltip/tooltip.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,46 @@ the positions `before` and `after` should be used instead of `left` and `right`,
2020
| `before` | Display to the left in left-to-right layout and to the right in right-to-left layout |
2121
| `after` | Display to the right in left-to-right layout and to the right in right-to-left layout|
2222

23+
<!-- example(tooltip-position) -->
2324

2425
### Showing and hiding
2526

26-
The tooltip is immediately shown when the user's mouse hovers over the element and immediately
27-
hides when the user's mouse leaves. A delay in showing or hiding the tooltip can be added through
28-
the inputs `matTooltipShowDelay` and `matTooltipHideDelay`. The default show and hide delays can be
29-
configured through the `MAT_TOOLTIP_DEFAULT_OPTIONS` injection token.
27+
By default, the tooltip will be immediately shown when the user's mouse hovers over the tooltip's
28+
trigger element and immediately hides when the user's mouse leaves.
3029

3130
On mobile, the tooltip is displayed when the user longpresses the element and hides after a
32-
delay of 1500ms. The longpress behavior requires HammerJS to be loaded on the page.
31+
delay of 1500ms. The longpress behavior requires HammerJS to be loaded on the page. To learn more
32+
about adding HammerJS to your app, check out the Gesture Support section of the Getting Started
33+
guide.
3334

34-
The tooltip can also be shown and hidden through the `show` and `hide` directive methods,
35+
#### Show and hide delays
36+
37+
To add a delay before showing or hiding the tooltip, you can use the inputs `matTooltipShowDelay`
38+
and `matTooltipHideDelay` to provide a delay time in milliseconds.
39+
40+
The following example has a tooltip that waits one second to display after the user
41+
hovers over the button, and waits two seconds to hide after the user moves the mouse away.
42+
43+
<!-- example(tooltip-delay) -->
44+
45+
#### Changing the default delay behavior
46+
47+
You can configure your app's tooltip default show/hide delays by configuring and providing
48+
your options using the `MAT_TOOLTIP_DEFAULT_OPTIONS` injection token.
49+
50+
<!-- example(tooltip-modified-defaults) -->
51+
52+
#### Manually calling show() and hide()
53+
54+
To manually cause the tooltip to show or hide, you can call the `show` and `hide` directive methods,
3555
which both accept a number in milliseconds to delay before applying the display change.
3656

37-
To turn off the tooltip and prevent it from showing to the user, use the `matTooltipDisabled` input
38-
flag.
57+
<!-- example(tooltip-manual) -->
58+
59+
#### Disabling the tooltip from showing
60+
61+
To completely disable a tooltip, set `matTooltipDisabled`. While disabled, a tooltip will never be
62+
shown.
3963

4064
### Accessibility
4165

src/material-examples/example-module.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ import {TabsTemplateLabelExample} from './tabs-template-label/tabs-template-labe
119119
import {ToolbarMultirowExample} from './toolbar-multirow/toolbar-multirow-example';
120120
import {ToolbarOverviewExample} from './toolbar-overview/toolbar-overview-example';
121121
import {TooltipOverviewExample} from './tooltip-overview/tooltip-overview-example';
122+
import {TooltipDelayExample} from './tooltip-delay/tooltip-delay-example';
122123
import {TooltipPositionExample} from './tooltip-position/tooltip-position-example';
124+
import {TooltipManualExample} from './tooltip-manual/tooltip-manual-example';
125+
import {TooltipModifiedDefaultsExample} from './tooltip-modified-defaults/tooltip-modified-defaults-example';
123126

124127
export interface LiveExample {
125128
title: string;
@@ -597,6 +600,18 @@ export const EXAMPLE_COMPONENTS: {[key: string]: LiveExample} = {
597600
title: 'Basic tooltip',
598601
component: TooltipOverviewExample
599602
},
603+
'tooltip-delay': {
604+
title: 'Tooltips with delay',
605+
component: TooltipDelayExample
606+
},
607+
'tooltip-manual': {
608+
title: 'Tooltips with manual show button',
609+
component: TooltipManualExample
610+
},
611+
'tooltip-modified-defaults': {
612+
title: 'Tooltips with modified default values',
613+
component: TooltipModifiedDefaultsExample
614+
},
600615
'tooltip-position': {
601616
title: 'Tooltip with custom position',
602617
component: TooltipPositionExample
@@ -718,6 +733,9 @@ export const EXAMPLE_LIST = [
718733
ToolbarMultirowExample,
719734
ToolbarOverviewExample,
720735
TooltipOverviewExample,
736+
TooltipDelayExample,
737+
TooltipManualExample,
738+
TooltipModifiedDefaultsExample,
721739
TooltipPositionExample,
722740
];
723741

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
button {
2+
margin: 8px;
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<button mat-raised-button matTooltip="Tooltip!" matTooltipShowDelay="1000">
2+
My tooltip waits one second to show
3+
</button>
4+
5+
<button mat-raised-button matTooltip="Tooltip!" matTooltipHideDelay="2000">
6+
My tooltip waits two seconds to hide
7+
</button>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title Tooltip with a show and hide delay
5+
*/
6+
@Component({
7+
selector: 'tooltip-delay-example',
8+
templateUrl: 'tooltip-delay-example.html',
9+
styleUrls: ['tooltip-delay-example.css'],
10+
})
11+
export class TooltipDelayExample {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<button mat-raised-button (click)="tooltip.show()"> Show tooltip </button>
2+
3+
<span matTooltip="This is the tooltip message" #tooltip="matTooltip">
4+
I have a tooltip
5+
</span>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title Tooltip that can be manually shown/hidden.
5+
*/
6+
@Component({
7+
selector: 'tooltip-manual-example',
8+
templateUrl: 'tooltip-manual-example.html',
9+
styleUrls: ['tooltip-manual-example.css'],
10+
})
11+
export class TooltipManualExample {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<button mat-raised-button matTooltip="By default, I delay">
2+
Button with delay-default tooltip
3+
</button>

0 commit comments

Comments
 (0)