8000 Tooltip: Handle synthetic focusin events. Fixes #8740 - Tooltip: Does… · ProgramComputer/jquery-ui@f4ce4d3 · GitHub
Skip to content

Commit f4ce4d3

Browse files
committed
Tooltip: Handle synthetic focusin events. Fixes #8740 - Tooltip: Does not hide consistently with dynamically loaded content.
(cherry picked from commit 1b503a2)
1 parent 3175d7d commit f4ce4d3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

tests/unit/tooltip/tooltip_core.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,31 @@ test( "tooltip on .ui-state-disabled element", function() {
107107
equal( $( ".ui-tooltip" ).length, 0 );
108108
});
109109

110+
// http://bugs.jqueryui.com/ticket/8740
111+
asyncTest( "programmatic focus with async content", function() {
112+
expect( 2 );
113+
var element = $( "#tooltipped1" ).tooltip({
114+
content: function( response ) {
115+
setTimeout(function() {
116+
response( "test" );
117+
});
118+
}
119+
});
120+
121+
element.bind( "tooltipopen", function( event ) {
122+
deepEqual( event.originalEvent.type, "focusin" );
123+
124+
element.bind( "tooltipclose", function( event ) {
125+
deepEqual( event.originalEvent.type, "focusout" );
126+
start();
127+
});
128+
129+
setTimeout(function() {
130+
element.blur();
131+
});
132+
});
133+
134+
element.focus();
135+
});
136+
110137
}( jQuery ) );

ui/jquery.ui.tooltip.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ $.widget( "ui.tooltip", {
188188
_updateContent: function( target, event ) {
189189
var content,
190190
contentOption = this.options.content,
191-
that = this;
191+
that = this,
192+
eventType = event ? event.type : null;
192193

193194
if ( typeof contentOption === "string" ) {
194195
return this._open( event, target, contentOption );
@@ -202,6 +203,14 @@ $.widget( "ui.tooltip", {
202203
// IE may instantly serve a cached response for ajax requests
203204
// delay this call to _open so the other call to _open runs first
204205
that._delay(function() {
206+
// jQuery creates a special event for focusin when it doesn't
207+
// exist natively. To improve performance, the native event
208+
// object is reused and the type is changed. Therefore, we can't
209+
// rely on the type being correct after the event finished
210+
// bubbling, so we set it back to the previous value. (#8740)
211+
if ( event ) {
212+
event.type = eventType;
213+
}
205214
this._open( event, target, response );
206215
});
207216
});

0 commit comments

Comments
 (0)