-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tooltip): add tooltip animations #1644
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
fde1c89
to
b4d733a
Compare
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
|
||
export type TooltipPosition = 'before' | 'after' | 'above' | 'below'; | ||
|
||
/** Time in ms to delay before changing the tooltip visibility to hidden */ | ||
export const MATERIAL_TOOLTIP_HIDE_DELAY = 1500; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just TOOLTIP_HIDE_DELAY
; the context for "material" is implied
this._overlayRef = this._overlay.create(config); | ||
/** Shows/hides the tooltip */ | ||
toggle(): void { | ||
if (this._isTooltipVisible()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a ternary:
this._isTooltipVisible() ? this.hide() : this.show();
/** Property watched by the animation framework to show or hide the tooltip */ | ||
_visibility: TooltipVisibility; | ||
|
||
/** Set to true when interactions on the page should close the tooltip */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether interactions on the page should close the tooltip
return this._onHide.asObservable(); | ||
} | ||
|
||
/** Returns true if the tooltip is being displayed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether the tooltip is being displayed
}) | ||
export class TooltipComponent { | ||
message: string; | ||
_handleBodyInteraction(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment with explanation for this behavior pointing to the spec.
}) | ||
export class MdTooltip { | ||
visible: boolean = false; | ||
_overlayRef: OverlayRef; | ||
_tooltipRef: TooltipComponent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be named something like _tooltipInstance
(though I'm thinking we should rename TooltipComponent
to something like TooltipContainer
, in which case this would be the more sensible _tooltipContainerInstance
)
this._hideTimeoutId = setTimeout(() => { | ||
this._visibility = 'hidden'; | ||
this._closeOnInteraction = false; | ||
}, delay); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for show()
being called while hide()
is in-progress?
Comments addressed, added test for showing before the hide delay. Ready for review. Would like to add tests that trigger after the animation is completed but it doesn't seem to be firing. |
|
||
describe('MdTooltip', () => { | ||
fdescribe('MdTooltip', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fdescribe
and fit
ViewContainerRef, | ||
ChangeDetectorRef | ||
NgModule, ModuleWithProviders, Component, Directive, Input, ElementRef, ViewContainerRef, | ||
style, trigger, state, transition, animate, AnimationTransitionEvent, NgZone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are generally wrapped to be one-per line; WebStorm's Optimize imports
command should do this automatically (though it always removes the trailing comma and uses 4 spaces).
b0cb8ed
to
fb12452
Compare
Thanks for the comments, I removed the fdescribe and updated the imports |
Realized I needed a detectChanges to trigger the done animation and then used fixture.whenStable() to test for the observable trigger that follows. Change is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple more things
expect(tooltipDirective._isTooltipVisible()).toBe(false); | ||
|
||
// On animation complete, should expect that the tooltip has been detached. | ||
fixture.whenStable().then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need whenStable
with fakeAsync
, since you're in control of ticking the clock.
(unless there's something special going on with ngAnimate that I don't know about)
if (this._overlayRef) { | ||
this._changeDetectionRef.detectChanges(); | ||
this._overlayRef.updatePosition(); | ||
_handleBodyInteraction(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this a little more, and started worry that this will be a performance problem- every instance of tooltip will add a handler that will run on every click in the application, which could add up to a slowdown. I'm thinking now that it would be better to directly add and remove the click handler when the tooltip is shown/hidden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, this is happens because the parent will create an overlay w/ tooltip on show, and detach the tooltip when the tooltip finishes the hide animation. Would you like this behavior to be implemented explicitly in the tooltip component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think moving the handler to TooltipComponent
would solve the issue
9363443
to
71f7d42
Compare
LGTM |
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {TooltipPosition, MdTooltip} from './tooltip'; | ||
import {TooltipPosition, MdTooltip, TOOLTIP_HIDE_DELAY, MdTooltipModule} from './tooltip'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you globally configure TOOLTIP_HIDE_DELAY
?
@rolandjitsu can you open an issue requesting that? |
@jelbourn sure thing 👍 |
Check out #1806 to track the issue |
|
||
/** Disposes the current tooltip and the overlay it is attached to */ | ||
private _disposeTooltip(): void { | ||
this._overlayRef.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am seeming some TypeError: this._overlayRef is null
here, I think it originates from here, not 100% sure. Is this a known issue or is there need for one to be opened?
I haven't seen this issue, please open an issue with how to reproduce On Thu, Nov 10, 2016 at 10:02 AM Roland Groza notifications@github.com
|
@andrewseguin I just opened a bunch more issues :) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adding animations to the tooltip