Skip to content

Tooltip: Don't crash on empty content #1994

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

Merged
merged 7 commits into from
Nov 8, 2021
Merged
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
70 changes: 70 additions & 0 deletions tests/unit/tooltip/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,74 @@ QUnit.test( "remove conflicting attributes from live region", function( assert )
.tooltip( "open" );
} );

// gh-1990
QUnit.test( "don't crash on empty tooltip content", function( assert ) {
var ready = assert.async();
assert.expect( 1 );

var anchor = $( "#tooltipped1" ),
input = anchor.next(),
actions = [];

$( document ).tooltip( {
show: false,
hide: false,
content: function() {
var title = $( this ).attr( "title" );
if ( title === "inputtitle" ) {
return "";
}
return title;
},
open: function( event, ui ) {
actions.push( "open:" + ui.tooltip.text() );
},
close: function( event, ui ) {
actions.push( "close:" + ui.tooltip.text() );
}
} );

function step1() {
anchor.simulate( "mouseover" );
setTimeout( step2 );
}

function step2() {
anchor.simulate( "mouseout" );
setTimeout( step3 );
}

function step3() {
input.simulate( "focus" );
setTimeout( step4 );
}

function step4() {
input.simulate( "blur" );
setTimeout( step5 );
}

function step5() {
anchor.simulate( "mouseover" );
setTimeout( step6 );
}

function step6() {
anchor.simulate( "mouseout" );
setTimeout( step7 );
}

function step7() {
assert.deepEqual( actions, [
"open:anchortitle",
"close:anchortitle",
"open:anchortitle",
"close:anchortitle"
], "Tooltip opens and closes without crashing" );
ready();
}

step1();
} );

} );
5 changes: 4 additions & 1 deletion ui/widgets/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ $.widget( "ui.tooltip", {
// tooltips will handle this in destroy.
if ( target[ 0 ] !== this.element[ 0 ] ) {
events.remove = function() {
this._removeTooltip( this._find( target ).tooltip );
var targetElement = this._find( target );
if ( targetElement ) {
this._removeTooltip( targetElement.tooltip );
}
};
}

Expand Down