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

Commit 041261b

Browse files
pkozlowski-opensourceJosh David Miller
authored and
Josh David Miller
committed
fix(tooltip): close tooltips appended to body on location change
Closes #345
1 parent 76fee1f commit 041261b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/tooltip/test/tooltip.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,26 @@ describe( '$tooltipProvider', function() {
309309
expect( elmBody.children().length ).toBe( 1 );
310310
expect( $body.children().length ).toEqual( bodyLength + 1 );
311311
}));
312+
313+
it('should close on location change', inject( function( $rootScope, $compile) {
314+
315+
elmBody = angular.element(
316+
'<div><span tooltip="tooltip text">Selector Text</span></div>'
317+
);
318+
319+
scope = $rootScope;
320+
$compile(elmBody)(scope);
321+
scope.$digest();
322+
elm = elmBody.find('span');
323+
elmScope = elm.scope();
324+
325+
elm.trigger( 'mouseenter' );
326+
expect( elmScope.tt_isOpen ).toBe( true );
327+
328+
scope.$broadcast('$locationChangeSuccess');
329+
scope.$digest();
330+
expect( elmScope.tt_isOpen ).toBe( false );
331+
}));
312332
});
313333

314334
describe( 'triggers', function() {

src/tooltip/tooltip.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
266266
element.bind( triggers.hide, hideTooltipBind );
267267
}
268268
});
269+
270+
//if a tooltip is attached to <body> we need to remove it on location change
271+
if ( options.appendToBody ) {
272+
scope.$on('$locationChangeSuccess', hide);
273+
}
269274
}
270275
};
271276
};
@@ -296,7 +301,4 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
296301

297302
.directive( 'tooltipHtmlUnsafe', [ '$tooltip', function ( $tooltip ) {
298303
return $tooltip( 'tooltipHtmlUnsafe', 'tooltip', 'mouseenter' );
299-
}])
300-
301-
;
302-
304+
}]);

0 commit comments

Comments
 (0)