Skip to content

Commit 32bef7a

Browse files
committed
Tooltip: Treat the tooltip as closing until it's fully removed
This ensures that we don't trigger the close event twice if the tooltip is destroyed during the hide animation. Closes gh-1306
1 parent d157b66 commit 32bef7a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/unit/tooltip/tooltip_core.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,24 @@ asyncTest( "programmatic focus with async content", function() {
154154
element.focus();
155155
});
156156

157+
asyncTest( "destroy during hide animation; only one close event", function() {
158+
expect( 1 );
159+
160+
var element = $( "#tooltipped1" ).tooltip({
161+
show: false,
162+
hide: true
163+
});
164+
165+
element.bind( "tooltipclose", function() {
166+
ok( true, "tooltip closed" );
167+
});
168+
169+
element.tooltip( "open" );
170+
element.tooltip( "close" );
171+
setTimeout(function() {
172+
element.tooltip( "destroy" );
173+
start();
174+
});
175+
});
176+
157177
}( jQuery ) );

ui/tooltip.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ return $.widget( "ui.tooltip", {
296296
}, this.options.position ) );
297297
}
298298

299+
this.hiding = false;
300+
this.closing = false;
299301
tooltip.hide();
300302

301303
this._show( tooltip, this.options.show );
@@ -362,9 +364,12 @@ return $.widget( "ui.tooltip", {
362364

363365
this._removeDescribedBy( target );
364366

367+
this.hiding = true;
365368
tooltip.stop( true );
366369
this._hide( tooltip, this.options.hide, function() {
367370
that._removeTooltip( $( this ) );
371+
this.hiding = false;
372+
this.closing = false;
368373
});
369374

370375
target.removeData( "ui-tooltip-open" );
@@ -385,7 +390,9 @@ return $.widget( "ui.tooltip", {
385390

386391
this.closing = true;
387392
this._trigger( "close", event, { tooltip: tooltip } );
388-
this.closing = false;
393+
if ( !this.hiding ) {
394+
this.closing = false;
395+
}
389396
},
390397

391398
_tooltip: function( element ) {

0 commit comments

Comments
 (0)