Skip to content

Commit 6b48ef5

Browse files
committed
Tooltip: Only bind blur when opening via focus, mouseleave for mouseover. Remove the keep-open-on-focusout workaround. Now matching behaviour described in ARIA Authoring Practices. Fixes #8699 - Moving focus on click of a tooltipped element shows native tooltip in IE/Firefox on Windows
1 parent 77a55f1 commit 6b48ef5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

tests/visual/tooltip/tooltip.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
offset: "0 -5"
9191
}
9292
});
93+
94+
$( "#blurs-on-click" ).tooltip().click(function() {
95+
$( "#focus-on-me" ).focus();
96+
});
9397
});
9498
</script>
9599
</head>
@@ -154,6 +158,9 @@
154158
</div>
155159
</div>
156160

161+
<button id="blurs-on-click" title="button title text">click me to focus something else</button>
162+
<input id="focus-on-me">
163+
157164
<div class="group">
158165
<p>Play around with focusing and hovering of form elements.</p>
159166
<form>

ui/jquery.ui.tooltip.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ $.widget( "ui.tooltip", {
206206
},
207207

208208
_open: function( event, target, content ) {
209-
var tooltip, positionOption;
209+
var tooltip, positionOption, events;
210210
if ( !content ) {
211211
return;
212212
}
@@ -261,17 +261,22 @@ $.widget( "ui.tooltip", {
261261

262262
this._trigger( "open", event, { tooltip: tooltip } );
263263

264-
this._on( target, {
265-
mouseleave: "close",
266-
focusout: "close",
264+
events = {
267265
keyup: function( event ) {
268266
if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
269267
var fakeEvent = $.Event(event);
270268
fakeEvent.currentTarget = target[0];
271269
this.close( fakeEvent, true );
272270
}
273271
}
274-
});
272+
};
273+
if ( !event || event.type === "mouseover" ) {
274+
events.mouseleave = "close";
275+
}
276+
if ( !event || event.type === "focusin" ) {
277+
events.focusout = "close";
278+
}
279+
this._on( target, events );
275280
},
276281

277282
close: function( event, force ) {
@@ -285,16 +290,6 @@ $.widget( "ui.tooltip", {
285290
return;
286291
}
287292

288-
// don't close if the element has focus
289-
// this prevents the tooltip from closing if you hover while focused
290-
//
291-
// we have to check the event type because tabbing out of the document
292-
// may leave the element as the activeElement
293-
if ( !force && event && event.type !== "focusout" &&
294-
this.document[0].activeElement === target[0] ) {
295-
return;
296-
}
297-
298293
// only set title if we had one before (see comment in _open())
299294
if ( target.data( "ui-tooltip-title" ) ) {
300295
target.attr( "title", target.data( "ui-tooltip-title" ) );

0 commit comments

Comments
 (0)