Skip to content

Commit 87781ce

Browse files
Stepan Rihaayakovlevgh
Stepan Riha
authored andcommitted
feat(tooltip): Support for tooltip-class configuration
Closes angular-ui#3126.
1 parent ed5959c commit 87781ce

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

Diff for: src/tooltip/docs/demo.html

+22-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,36 @@
1010
<p>
1111
Pellentesque <a href="#" tooltip="{{dynamicTooltip}}">{{dynamicTooltipText}}</a>,
1212
sit amet venenatis urna cursus eget nunc scelerisque viverra mauris, in
13-
aliquam. Tincidunt lobortis feugiat vivamus at
13+
aliquam. Tincidunt lobortis feugiat vivamus at
1414
<a href="#" tooltip-placement="left" tooltip="On the Left!">left</a> eget
1515
arcu dictum varius duis at consectetur lorem. Vitae elementum curabitur
16-
<a href="#" tooltip-placement="right" tooltip="On the Right!">right</a>
17-
nunc sed velit dignissim sodales ut eu sem integer vitae. Turpis egestas
18-
<a href="#" tooltip-placement="bottom" tooltip="On the Bottom!">bottom</a>
19-
pharetra convallis posuere morbi leo urna,
16+
<a href="#" tooltip-placement="right" tooltip="On the Right!">right</a>
17+
nunc sed velit dignissim sodales ut eu sem integer vitae. Turpis egestas
18+
<a href="#" tooltip-placement="bottom" tooltip="On the Bottom!">bottom</a>
19+
pharetra convallis posuere morbi leo urna,
2020
<a href="#" tooltip-animation="false" tooltip="I don't fade. :-(">fading</a>
2121
at elementum eu, facilisis sed odio morbi quis commodo odio. In cursus
2222
<a href="#" tooltip-popup-delay='1000' tooltip='appears with delay'>delayed</a> turpis massa tincidunt dui ut.
2323
</p>
2424

2525
<p>
26-
I can even contain HTML. <a href="#" tooltip-html-unsafe="{{htmlTooltip}}">Check me out!</a>
26+
I can even contain HTML. <a href="#" tooltip-html-unsafe="{{htmlTooltip}}">Check me out!</a>
27+
</p>
28+
29+
<p>
30+
<style>
31+
/* Specify styling for tooltip contents */
32+
.tooltip.customClass .tooltip-inner {
33+
color: #880000;
34+
background-color: #ffff66;
35+
box-shadow: 0 6px 12px rgba(0,0,0,.175);
36+
}
37+
/* Hide arrow */
38+
.tooltip.customClass .tooltip-arrow {
39+
display: none;
40+
}
41+
</style>
42+
I can have a custom class. <a href="#" tooltip="I can have a custom class applied to me!" tooltip-class="customClass">Check me out!</a>
2743
</p>
2844

2945
<form role="form">

Diff for: src/tooltip/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ will display:
2121
`tooltip-trigger`.
2222
- `tooltip-append-to-body`: Should the tooltip be appended to `$body` instead of
2323
the parent element?
24+
- `tooltip-class`: Custom class to be applied to the tooltip.
2425

2526
The tooltip directives require the `$position` service.
2627

Diff for: src/tooltip/test/tooltip2.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ describe('tooltip directive', function () {
101101

102102
});
103103

104+
describe('class', function () {
105+
106+
it('can specify a custom class', function () {
107+
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-class="custom">Trigger here</span>');
108+
fragment.find('span').trigger( 'mouseenter' );
109+
110+
var ttipElement = fragment.find('div.tooltip');
111+
expect(fragment).toHaveOpenTooltips();
112+
expect(ttipElement).toHaveClass('custom');
113+
114+
closeTooltip(fragment.find('span'));
115+
expect(fragment).not.toHaveOpenTooltips();
116+
});
117+
118+
});
119+
104120
});
105121

106122
it('should show even after close trigger is called multiple times - issue #1847', function () {
@@ -144,5 +160,4 @@ describe('tooltip directive', function () {
144160
// One needs to flush deferred functions before checking there is no tooltip.
145161
expect(fragment).not.toHaveOpenTooltips();
146162
});
147-
148163
});

Diff for: src/tooltip/tooltip.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
100100
'title="'+startSym+'title'+endSym+'" '+
101101
'content="'+startSym+'content'+endSym+'" '+
102102
'placement="'+startSym+'placement'+endSym+'" '+
103+
'class="'+startSym+'class'+endSym+'" '+
103104
'animation="animation" '+
104105
'is-open="isOpen"'+
105106
'>'+
@@ -276,6 +277,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
276277
ttScope.title = val;
277278
});
278279

280+
attrs.$observe( prefix+'Class', function ( val ) {
281+
ttScope.class = val;
282+
});
283+
279284
function prepPlacement() {
280285
var val = attrs[ prefix + 'Placement' ];
281286
ttScope.placement = angular.isDefined( val ) ? val : options.placement;
@@ -343,7 +348,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
343348
return {
344349
restrict: 'EA',
345350
replace: true,
346-
scope: { content: '@', placement: '@', animation: '&', isOpen: '&' },
351+
scope: { content: '@', placement: '@', class: '@', animation: '&', isOpen: '&' },
347352
templateUrl: 'template/tooltip/tooltip-popup.html'
348353
};
349354
})
@@ -356,7 +361,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
356361
return {
357362
restrict: 'EA',
358363
replace: true,
359-
scope: { content: '@', placement: '@', animation: '&', isOpen: '&' },
364+
scope: { content: '@', placement: '@', class: '@', animation: '&', isOpen: '&' },
360365
templateUrl: 'template/tooltip/tooltip-html-unsafe-popup.html'
361366
};
362367
})

Diff for: template/tooltip/tooltip-html-unsafe-popup.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="tooltip {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
1+
<div class="tooltip {{placement}} {{class}}" ng-class="{ in: isOpen(), fade: animation() }">
22
<div class="tooltip-arrow"></div>
33
<div class="tooltip-inner" bind-html-unsafe="content"></div>
44
</div>

Diff for: template/tooltip/tooltip-popup.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="tooltip {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
1+
<div class="tooltip {{placement}} {{class}}" ng-class="{ in: isOpen(), fade: animation() }">
22
<div class="tooltip-arrow"></div>
33
<div class="tooltip-inner" ng-bind="content"></div>
44
</div>

0 commit comments

Comments
 (0)