Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit d50b054

Browse files
psgibbspkozlowski-opensource
authored andcommitted
fix(tooltip): bind correct 'hide' event handler
If a user defines a tooltip-trigger attribute, this ensures the correct event handlers is used to hide the tooltip. Fixes a bug where if a user sets both a default trigger using the tooltip provider, and then tries to override with an attribute, the wrong 'hide' event was being used.
1 parent 4fd5bf4 commit d50b054

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/tooltip/test/tooltip.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,24 @@ describe( '$tooltipProvider', function() {
493493
elm.trigger('blur');
494494
expect( elmScope.tt_isOpen ).toBeFalsy();
495495
}));
496+
497+
it( 'should override the show and hide triggers if there is an attribute', inject( function ( $rootScope, $compile ) {
498+
elmBody = angular.element(
499+
'<div><input tooltip="tooltip text" tooltip-trigger="mouseenter"/></div>'
500+
);
501+
502+
scope = $rootScope;
503+
$compile(elmBody)(scope);
504+
scope.$digest();
505+
elm = elmBody.find('input');
506+
elmScope = elm.scope();
507+
508+
expect( elmScope.tt_isOpen ).toBeFalsy();
509+
elm.trigger('mouseenter');
510+
expect( elmScope.tt_isOpen ).toBeTruthy();
511+
elm.trigger('mouseleave');
512+
expect( elmScope.tt_isOpen ).toBeFalsy();
513+
}));
496514
});
497515

498516
describe( 'triggers with a custom mapped value', function() {

src/tooltip/tooltip.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
8282
* undefined; otherwise, it uses the `triggerMap` value of the show
8383
* trigger; else it will just use the show trigger.
8484
*/
85-
function setTriggers ( trigger ) {
86-
var show, hide;
87-
88-
show = trigger || options.trigger || defaultTriggerShow;
89-
if ( angular.isDefined ( options.trigger ) ) {
90-
hide = triggerMap[options.trigger] || show;
91-
} else {
92-
hide = triggerMap[show] || show;
93-
}
94-
85+
function getTriggers ( trigger ) {
86+
var show = trigger || options.trigger || defaultTriggerShow;
87+
var hide = triggerMap[show] || show;
9588
return {
9689
show: show,
9790
hide: hide
@@ -121,7 +114,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
121114
var popupTimeout;
122115
var $body;
123116
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
124-
var triggers = setTriggers( undefined );
117+
var triggers = getTriggers( undefined );
125118
var hasRegisteredTriggers = false;
126119

127120
// By default, the tooltip is not open.
@@ -283,7 +276,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
283276
element.unbind( triggers.hide, hideTooltipBind );
284277
}
285278

286-
triggers = setTriggers( val );
279+
triggers = getTriggers( val );
287280

288281
if ( triggers.show === triggers.hide ) {
289282
element.bind( triggers.show, toggleTooltipBind );

0 commit comments

Comments
 (0)