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

Commit 5d9bd05

Browse files
sohaipkozlowski-opensource
sohai
authored andcommitted
feat(tooltip): add ability to enable / disable tooltip
1 parent cf5c27a commit 5d9bd05

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/tooltip/test/tooltip.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ describe('tooltip', function() {
132132
expect( elmBody.children().length ).toBe( 0 );
133133
}));
134134

135+
describe('with specified enable expression', function() {
136+
137+
beforeEach(inject(function ($compile) {
138+
scope.enable = false;
139+
elmBody = $compile(angular.element(
140+
'<div><span tooltip="tooltip text" tooltip-enable="enable">Selector Text</span></div>'
141+
))(scope);
142+
scope.$digest();
143+
elm = elmBody.find('span');
144+
elmScope = elm.scope();
145+
146+
}));
147+
148+
it('should not open ', inject(function () {
149+
150+
elm.trigger('mouseenter');
151+
expect(elmScope.tt_isOpen).toBeFalsy();
152+
expect(elmBody.children().length).toBe(1);
153+
154+
}));
155+
156+
it('should open', inject(function () {
157+
158+
scope.enable = true;
159+
scope.$digest();
160+
elm.trigger('mouseenter');
161+
expect(elmScope.tt_isOpen).toBeTruthy();
162+
expect(elmBody.children().length).toBe(2);
163+
164+
}));
165+
});
166+
135167
describe('with specified popup delay', function () {
136168

137169
beforeEach(inject(function ($compile) {

src/tooltip/tooltip.js

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
116116
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
117117
var triggers = getTriggers( undefined );
118118
var hasRegisteredTriggers = false;
119+
var hasEnableExp = angular.isDefined(attrs[prefix+'Enable']);
119120

120121
// By default, the tooltip is not open.
121122
// TODO add ability to start tooltip opened
@@ -131,6 +132,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
131132

132133
// Show the tooltip with delay if specified, otherwise show it immediately
133134
function showTooltipBind() {
135+
if(hasEnableExp && !scope.$eval(attrs[prefix+'Enable'])) {
136+
return;
137+
}
134138
if ( scope.tt_popupDelay ) {
135139
popupTimeout = $timeout( show, scope.tt_popupDelay );
136140
} else {

0 commit comments

Comments
 (0)