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

Commit ab44a86

Browse files
Josh David Millerpkozlowski-opensource
Josh David Miller
authored andcommitted
fix(tooltip): Transcludes contents to allow dynamic selector text
A dynamic selector did not work as the contents of the directive element were not transcluded. This fix adds transclusion through a new directive controller method. It also includes a new test for this case (through an ngRepeat) as well as a modified demo to show this use case. Closes #69
1 parent 1895690 commit ab44a86

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/tooltip/docs/demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<div ng-controller="TooltipDemoCtrl">
22
<div class="well">
3-
<div>Dynamic Tooltip Text: <input ng-model="dynamicTooltip"></input></div>
3+
<div>Dynamic Tooltip Text: <input ng-model="dynamicTooltipText"></input></div>
4+
<div>Dynamic Tooltip Popup Text: <input ng-model="dynamicTooltip"></input></div>
45
<p>
5-
Pellentesque <a><span tooltip="{{dynamicTooltip}}">dynamic</span></a>,
6+
Pellentesque <a><span tooltip="{{dynamicTooltip}}">{{dynamicTooltipText}}</span></a>,
67
sit amet venenatis urna cursus eget nunc scelerisque viverra mauris, in
78
aliquam. Tincidunt lobortis feugiat vivamus at
89
<a><span tooltip-placement="left" tooltip="On the Left!">left</span></a> eget

src/tooltip/docs/demo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
var TooltipDemoCtrl = function ($scope) {
22
$scope.dynamicTooltip = "Hello, World!";
3+
$scope.dynamicTooltipText = "dynamic";
34
};

src/tooltip/test/tooltipSpec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ describe('tooltip', function() {
6060
expect( elmScope.placement ).toBe( "bottom" );
6161
}));
6262

63+
it('should work inside an ngRepeat', inject( function( $compile ) {
64+
65+
elm = $compile( angular.element(
66+
'<ul>'+
67+
'<li ng-repeat="item in items">'+
68+
'<span id="selector" tooltip="{{item.tooltip}}">{{item.name}}</span>'+
69+
'</li>'+
70+
'</ul>'
71+
) )( scope );
72+
73+
scope.items = [
74+
{ name: "One", tooltip: "First Tooltip" }
75+
];
76+
77+
scope.$digest();
78+
79+
var tt = angular.element( elm.find("li > span")[0] );
80+
81+
tt.trigger( 'mouseenter' );
82+
83+
// Due to the transclusion, the contents of the element are in a span, so
84+
// we select the tooltip's child and ensure its content matches.
85+
expect( tt.children().text() ).toBe( scope.items[0].name );
86+
87+
// And the tooltip text should still match.
88+
expect( tt.scope().tooltipTitle ).toBe( scope.items[0].tooltip );
89+
90+
tt.trigger( 'mouseleave' );
91+
}));
6392
});
6493

6594

src/tooltip/tooltip.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ angular.module( 'ui.bootstrap.tooltip', [] )
1717
'<tooltip-popup></tooltip-popup>';
1818

1919
return {
20+
transclude: true,
2021
scope: { tooltipTitle: '@tooltip', placement: '@tooltipPlacement', animation: '&tooltipAnimation' },
22+
controller: ['$transclude', '$element', function($transclude, $element) {
23+
$transclude(function(clone) {
24+
$element.append(clone);
25+
});
26+
}],
2127
link: function ( scope, element, attr ) {
2228
var tooltip = $compile( template )( scope ),
2329
transitionTimeout;

0 commit comments

Comments
 (0)