diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-05-29 19:21:31 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-05-29 19:21:31 -0400 |
commit | 133fba2ad9b588233f7c7303619ac42351f08926 (patch) | |
tree | 9e409d95e73abebdbe4a276697ecc61b09fcd287 | |
parent | ade1fe18875dfec29a70072360841c5466663291 (diff) | |
download | jquery-ui-133fba2ad9b588233f7c7303619ac42351f08926.tar.gz jquery-ui-133fba2ad9b588233f7c7303619ac42351f08926.zip |
Tooltip: Don't close tooltips on mouseleave if the element is still focused.
-rw-r--r-- | tests/unit/tooltip/tooltip_events.js | 26 | ||||
-rw-r--r-- | ui/jquery.ui.tooltip.js | 7 |
2 files changed, 31 insertions, 2 deletions
diff --git a/tests/unit/tooltip/tooltip_events.js b/tests/unit/tooltip/tooltip_events.js index 515760b28..61026882e 100644 --- a/tests/unit/tooltip/tooltip_events.js +++ b/tests/unit/tooltip/tooltip_events.js @@ -47,4 +47,30 @@ test( "focus events", function() { element.trigger( "blur" ); }); +test( "mixed events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "focusin" ); + }); + element[0].focus(); + + element.one( "tooltipopen", function() { + ok( false, "open triggered while already open" ); + }); + element.trigger( "mouseover" ); + + element.bind( "tooltipclose", function( event ) { + ok( false, "close triggered while still focused" ); + }); + element.trigger( "mouseleave" ); + element.unbind( "tooltipclose" ); + + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "blur" ); + }); + element[0].blur(); +}); + }( jQuery ) ); diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index c5d9508f7..44398a871 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -56,7 +56,8 @@ $.widget( "ui.tooltip", { target = $( event ? event.target : this.element ) .closest( this.options.items ); - if ( !target.length ) { + // if aria-describedby exists, then the tooltip is already open + if ( !target.length || target.attr( "aria-describedby" ) ) { return; } @@ -131,7 +132,9 @@ $.widget( "ui.tooltip", { target.attr( "title", target.data( "tooltip-title" ) ); } - if ( this.options.disabled ) { + // don't close if the element has focus + // this prevents the tooltip from closing if you hover while focused + if ( this.options.disabled || document.activeElement === target[0] ) { return; } |