Skip to content

Commit 1552d70

Browse files
andrewseguinkara
authored andcommitted
feat(tooltip): show tooltip on longpress; remove delay on mouseleave (#1819)
1 parent d7a54ef commit 1552d70

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import {
2-
async, ComponentFixture, TestBed, tick, fakeAsync,
2+
async,
3+
ComponentFixture,
4+
TestBed,
5+
tick,
6+
fakeAsync,
37
flushMicrotasks
48
} from '@angular/core/testing';
59
import {Component, DebugElement, AnimationTransitionEvent} from '@angular/core';
610
import {By} from '@angular/platform-browser';
7-
import {TooltipPosition, MdTooltip, TOOLTIP_HIDE_DELAY, MdTooltipModule} from './tooltip';
11+
import {TooltipPosition, MdTooltip, MdTooltipModule} from './tooltip';
812
import {OverlayContainer} from '../core';
913

1014
const initialTooltipMessage = 'initial tooltip message';
@@ -52,11 +56,12 @@ describe('MdTooltip', () => {
5256
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
5357

5458
// After hide called, a timeout delay is created that will to hide the tooltip.
55-
tooltipDirective.hide();
59+
const tooltipDelay = 1000;
60+
tooltipDirective.hide(tooltipDelay);
5661
expect(tooltipDirective._isTooltipVisible()).toBe(true);
5762

5863
// After the tooltip delay elapses, expect that the tooltip is not visible.
59-
tick(TOOLTIP_HIDE_DELAY);
64+
tick(tooltipDelay);
6065
fixture.detectChanges();
6166
expect(tooltipDirective._isTooltipVisible()).toBe(false);
6267

@@ -70,12 +75,13 @@ describe('MdTooltip', () => {
7075
expect(tooltipDirective._isTooltipVisible()).toBe(true);
7176

7277
// After hide called, a timeout delay is created that will to hide the tooltip.
73-
tooltipDirective.hide();
78+
const tooltipDelay = 1000;
79+
tooltipDirective.hide(tooltipDelay);
7480
expect(tooltipDirective._isTooltipVisible()).toBe(true);
7581

7682
// Before delay time has passed, call show which should cancel intent to hide tooltip.
7783
tooltipDirective.show();
78-
tick(TOOLTIP_HIDE_DELAY);
84+
tick(tooltipDelay);
7985
expect(tooltipDirective._isTooltipVisible()).toBe(true);
8086
}));
8187

src/lib/tooltip/tooltip.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {Subject} from 'rxjs/Subject';
3030
export type TooltipPosition = 'before' | 'after' | 'above' | 'below';
3131

3232
/** Time in ms to delay before changing the tooltip visibility to hidden */
33-
export const TOOLTIP_HIDE_DELAY = 1500;
33+
export const TOUCHEND_HIDE_DELAY = 1500;
3434

3535
/**
3636
* Directive that attaches a material design tooltip to the host element. Animates the showing and
@@ -41,6 +41,8 @@ export const TOOLTIP_HIDE_DELAY = 1500;
4141
@Directive({
4242
selector: '[md-tooltip]',
4343
host: {
44+
'(longpress)': 'show()',
45+
'(touchend)': 'hide(' + TOUCHEND_HIDE_DELAY + ')',
4446
'(mouseenter)': 'show()',
4547
'(mouseleave)': 'hide()',
4648
},
@@ -100,12 +102,8 @@ export class MdTooltip {
100102
this._tooltipInstance.show(this._position);
101103
}
102104

103-
/**
104-
* Create the overlay config and position strategy
105-
* Hides the tooltip after the provided delay in ms. Defaults the delay to the material design
106-
* prescribed delay time
107-
*/
108-
hide(delay: number = TOOLTIP_HIDE_DELAY): void {
105+
/** Hides the tooltip after the provided delay in ms, defaulting to 0ms. */
106+
hide(delay = 0): void {
109107
if (this._tooltipInstance) {
110108
this._tooltipInstance.hide(delay);
111109
}

0 commit comments

Comments
 (0)