Skip to content

Commit 133fba2

Browse files
committed
Tooltip: Don't close tooltips on mouseleave if the element is still focused.
1 parent ade1fe1 commit 133fba2

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tests/unit/tooltip/tooltip_events.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,30 @@ test( "focus events", function() {
4747
element.trigger( "blur" );
4848
});
4949

50+
test( "mixed events", function() {
51+
expect( 2 );
52+
var element = $( "#tooltipped1" ).tooltip();
53+
54+
element.one( "tooltipopen", function( event ) {
55+
same( event.originalEvent.type, "focusin" );
56+
});
57+
element[0].focus();
58+
59+
element.one( "tooltipopen", function() {
60+
ok( false, "open triggered while already open" );
61+
});
62+
element.trigger( "mouseover" );
63+
64+
element.bind( "tooltipclose", function( event ) {
65+
ok( false, "close triggered while still focused" );
66+
});
67+
element.trigger( "mouseleave" );
68+
element.unbind( "tooltipclose" );
69+
70+
element.one( "tooltipclose", function( event ) {
71+
same( event.originalEvent.type, "blur" );
72+
});
73+
element[0].blur();
74+
});
75+
5076
}( jQuery ) );

ui/jquery.ui.tooltip.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ $.widget( "ui.tooltip", {
5656
target = $( event ? event.target : this.element )
5757
.closest( this.options.items );
5858

59-
if ( !target.length ) {
59+
// if aria-describedby exists, then the tooltip is already open
60+
if ( !target.length || target.attr( "aria-describedby" ) ) {
6061
return;
6162
}
6263

@@ -131,7 +132,9 @@ $.widget( "ui.tooltip", {
131132
target.attr( "title", target.data( "tooltip-title" ) );
132133
}
133134

134-
if ( this.options.disabled ) {
135+
// don't close if the element has focus
136+
// this prevents the tooltip from closing if you hover while focused
137+
if ( this.options.disabled || document.activeElement === target[0] ) {
135138
return;
136139
}
137140

0 commit comments

Comments
 (0)