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

Commit 5f68280

Browse files
RobJacobswesleycho
authored andcommitted
fix(tooltip): isOpen to work with expressions
The is-open attribute should work with expressions as well as model values Closes #4380 Fixes #4362
1 parent c064748 commit 5f68280

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/tooltip/test/tooltip.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,28 @@ describe('tooltip', function() {
350350
});
351351
});
352352

353+
describe('with an is-open attribute expression', function() {
354+
beforeEach(inject(function ($compile) {
355+
scope.isOpen = false;
356+
elm = $compile(angular.element(
357+
'<span tooltip="tooltip text" tooltip-is-open="isOpen === true" >Selector Text</span>'
358+
))(scope);
359+
elmScope = elm.scope();
360+
tooltipScope = elmScope.$$childTail;
361+
scope.$digest();
362+
}));
363+
364+
it('should show and hide with the expression', function() {
365+
expect(tooltipScope.isOpen).toBe(false);
366+
elmScope.isOpen = true;
367+
elmScope.$digest();
368+
expect(tooltipScope.isOpen).toBe(true);
369+
elmScope.isOpen = false;
370+
elmScope.$digest();
371+
expect(tooltipScope.isOpen).toBe(false);
372+
});
373+
});
374+
353375
describe('with a trigger attribute', function() {
354376
var scope, elmBody, elm, elmScope;
355377

src/tooltip/tooltip.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position'])
221221

222222
// And show the tooltip.
223223
ttScope.isOpen = true;
224-
if (isOpenExp) {
224+
if (isOpenExp && angular.isFunction(isOpenExp.assign)) {
225225
isOpenExp.assign(ttScope.origScope, ttScope.isOpen);
226226
}
227227

@@ -240,7 +240,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position'])
240240

241241
// First things first: we don't show it anymore.
242242
ttScope.isOpen = false;
243-
if (isOpenExp) {
243+
if (isOpenExp && angular.isFunction(isOpenExp.assign)) {
244244
isOpenExp.assign(ttScope.origScope, ttScope.isOpen);
245245
}
246246

0 commit comments

Comments
 (0)