Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Fix animation end callback in manual mode #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions paper-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Polymer({
*/
attached: function() {
this._findTarget();
this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd');
},

/**
Expand All @@ -347,6 +348,7 @@ Polymer({
detached: function() {
if (!this.manualMode)
this._removeListeners();
this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd');
},

/**
Expand Down Expand Up @@ -496,7 +498,6 @@ Polymer({
this.listen(this._target, 'blur', 'hide');
this.listen(this._target, 'tap', 'hide');
}
this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd');
this.listen(this, 'mouseenter', 'hide');
},

Expand Down Expand Up @@ -582,7 +583,6 @@ Polymer({
this.unlisten(this._target, 'blur', 'hide');
this.unlisten(this._target, 'tap', 'hide');
}
this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd');
this.unlisten(this, 'mouseenter', 'hide');
}
});
23 changes: 23 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,29 @@
expect(tooltip._removeListeners.callCount).to.be.equal(1);
});

test('animation state is updated in manual-mode', function() {
var f = fixture('manual-mode');

var tooltip = f.querySelector('paper-tooltip');
assert.isTrue(tooltip.manualMode);
sinon.spy(tooltip, '_onAnimationEnd');

// Manually set the animation state for testing purposes
tooltip._animationPlaying = true;
assert.isTrue(tooltip._animationPlaying);

// Select the inner tooltip div and use it to simulate the end of its
// animation
var tooltipContainer = tooltip.shadowRoot.querySelector('#tooltip');

// Dispatch an event simulating the end of a tooltip animation and make
// sure that the callback has been executed and that the animation
// state has been updated
tooltipContainer.dispatchEvent(new CustomEvent('animationend'));
expect(tooltip._onAnimationEnd.callCount).to.be.equal(1);
assert.isFalse(tooltip._animationPlaying);
});

test('changing for= re-targets event listeners', function() {
var f = fixture('dynamic');
var tooltip = f.querySelector('paper-tooltip');
Expand Down