Skip to content
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

Merged
merged 12 commits into from
Nov 1, 2016

Conversation

andrewseguin
Copy link
Contributor

Adding animations to the tooltip

@googlebot
Copy link

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
@googlebot
Copy link

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.

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label Oct 28, 2016
@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Oct 28, 2016

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;
Copy link
Member

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()) {
Copy link
Member

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 */
Copy link
Member

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 */
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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?

@andrewseguin
Copy link
Contributor Author

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', () => {
Copy link
Member

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
Copy link
Member

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).

@andrewseguin
Copy link
Contributor Author

Thanks for the comments, I removed the fdescribe and updated the imports

@andrewseguin
Copy link
Contributor Author

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

Copy link
Member

@jelbourn jelbourn left a 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(() => {
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

@jelbourn
Copy link
Member

jelbourn commented Nov 1, 2016

LGTM

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Nov 1, 2016
@hansl hansl merged commit 52582f4 into angular:master Nov 1, 2016
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';

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?

@jelbourn
Copy link
Member

@rolandjitsu can you open an issue requesting that?

@rolandjitsu
Copy link

@jelbourn sure thing 👍

@andrewseguin
Copy link
Contributor Author

Check out #1806 to track the issue


/** Disposes the current tooltip and the overlay it is attached to */
private _disposeTooltip(): void {
this._overlayRef.dispose();

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?

@andrewseguin
Copy link
Contributor Author

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
wrote:

@rolandjitsu commented on this pull request.

In src/lib/tooltip/tooltip.ts
#1644 (review)
:

  • }
  • /** Create the overlay config and position strategy */
  • private _createOverlay(): void {
  • let origin = this._getOrigin();
  • let position = this._getOverlayPosition();
  • let strategy = this._overlay.position().connectedTo(this._elementRef, origin, position);
  • let config = new OverlayState();
  • config.positionStrategy = strategy;
  • this._overlayRef = this._overlay.create(config);
  • }
  • /** Disposes the current tooltip and the overlay it is attached to */
  • private _disposeTooltip(): void {
  • this._overlayRef.dispose();

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?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#1644 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AV1nkcKoqIYQy9Duxyctkvi2OUJged10ks5q81xNgaJpZM4Kj73R
.

@rolandjitsu
Copy link

@andrewseguin I just opened a bunch more issues :)

@andrewseguin andrewseguin deleted the tooltip-animate branch November 11, 2016 22:59
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants