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

Commit

Permalink
fix(tooltip): update tooltip placement dynamically
Browse files Browse the repository at this point in the history
Closes #3980
Fixes #3978
  • Loading branch information
cvn authored and wesleycho committed Aug 2, 2015
1 parent 632aa82 commit 13df1c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ describe('tooltip', function() {
expect( tooltipScope.placement ).toBe( 'bottom' );
}));

it('should update placement dynamically', inject( function( $compile, $timeout ) {
scope.place = 'bottom';
elm = $compile( angular.element(
'<span tooltip="tooltip text" tooltip-placement="{{place}}">Selector Text</span>'
) )( scope );
scope.$apply();
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'mouseenter' );
expect( tooltipScope.placement ).toBe( 'bottom' );

scope.place = 'right';
scope.$digest();
$timeout.flush();
expect(tooltipScope.placement).toBe( 'right' );
}));

it('should work inside an ngRepeat', inject( function( $compile ) {

elm = $compile( angular.element(
Expand Down
9 changes: 9 additions & 0 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
positionTooltipAsync();
});

attrs.$observe( prefix + 'Placement', function () {
if (ttScope.isOpen) {
$timeout(function () {
prepPlacement();
show()();
}, 0, false);
}
});

function prepPopupClass() {
ttScope.popupClass = attrs[prefix + 'Class'];
}
Expand Down

0 comments on commit 13df1c9

Please sign in to comment.