Skip to content

Commit 77a55f1

Browse files
committed
Tooltip: Fix nested tooltips (on hover) by closing parent tooltips and removing title attributes. Fixes #8700 - Overlapping tooltipped elements shows native tooltip for one of the elements
1 parent 9d5f91e commit 77a55f1

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

tests/visual/tooltip/tooltip.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@
140140
<div class="group" style="width: 300px;">
141141
<p>Nested elements.</p>
142142
<div id="context2">
143-
<div title="something else" style="border:1px solid red;">
143+
<div title="nested parent" style="border:1px solid red;">
144144
tooltipped
145-
<span title="something more" style="border:1px solid green; padding-left: 50px;">nested tooltipped</span>
145+
<span title="nested child" style="border:1px solid green; padding-left: 25px;">
146+
nested tooltipped
147+
<span title="nested nested child" style="border:1px solid blue; padding-left: 25px;">third level</span>
148+
</span>
146149
</div>
150+
<input title="nested input title">
147151
</div>
148152
<div id="childish" style="border: 1px solid black;" title="element with child elements">
149153
Text in <strong>bold</strong>.

ui/jquery.ui.tooltip.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ $.widget( "ui.tooltip", {
7373

7474
// IDs of generated tooltips, needed for destroy
7575
this.tooltips = {};
76+
// IDs of parent tooltips where we removed the title attribute
77+
this.parents = {};
7678
},
7779

7880
_setOption: function( key, value ) {
@@ -126,10 +128,11 @@ $.widget( "ui.tooltip", {
126128
},
127129

128130
open: function( event ) {
129-
var target = $( event ? event.target : this.element )
130-
// we need closest here due to mouseover bubbling,
131-
// but always pointing at the same event target
132-
.closest( this.options.items );
131+
var that = this,
132+
target = $( event ? event.target : this.element )
133+
// we need closest here due to mouseover bubbling,
134+
// but always pointing at the same event target
135+
.closest( this.options.items );
133136

134137
// No element to show a tooltip for
135138
if ( !target.length ) {
@@ -154,6 +157,26 @@ $.widget( "ui.tooltip", {
154157

155158
target.data( "tooltip-open", true );
156159

160+
// kill parent tooltips, custom or native, for hover
161+
if ( event && event.type === "mouseover" ) {
162+
target.parents().each(function() {
163+
var blurEvent;
164+
if ( $( this ).data( "tooltip-open" ) ) {
165+
blurEvent = $.Event( "blur" );
166+
blurEvent.target = blurEvent.currentTarget = this;
167+
that.close( blurEvent, true );
168+
}
169+
if ( this.title ) {
170+
$( this ).uniqueId();
171+
that.parents[ this.id ] = {
172+
element: this,
173+
title: this.title
174+
};
175+
this.title = "";
176+
}
177+
});
178+
}
179+
157180
this._updateContent( target, event );
158181
},
159182

@@ -289,6 +312,13 @@ $.widget( "ui.tooltip", {
289312
this._off( target, "mouseleave focusout keyup" );
290313
this._off( this.document, "mousemove" );
291314

315+
if ( event && event.type === "mouseleave" ) {
316+
$.each( this.parents, function( id, parent ) {
317+
parent.element.title = parent.title;
318+
delete that.parents[ id ];
319+
});
320+
}
321+
292322
this.closing = true;
293323
this._trigger( "close", event, { tooltip: tooltip } );
294324
this.closing = false;

0 commit comments

Comments
 (0)