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

fix(tooltip): isOpen to work with expressions #4380

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -350,6 +350,28 @@ describe('tooltip', function() {
});
});

describe('with an is-open attribute expression', function() {
beforeEach(inject(function ($compile) {
scope.isOpen = false;
elm = $compile(angular.element(
'<span tooltip="tooltip text" tooltip-is-open="isOpen === true" >Selector Text</span>'
))(scope);
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;
scope.$digest();
}));

it('should show and hide with the expression', function() {
expect(tooltipScope.isOpen).toBe(false);
elmScope.isOpen = true;
elmScope.$digest();
expect(tooltipScope.isOpen).toBe(true);
elmScope.isOpen = false;
elmScope.$digest();
expect(tooltipScope.isOpen).toBe(false);
});
});

describe('with a trigger attribute', function() {
var scope, elmBody, elm, elmScope;

4 changes: 2 additions & 2 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position'])

// And show the tooltip.
ttScope.isOpen = true;
if (isOpenExp) {
if (isOpenExp && angular.isFunction(isOpenExp.assign)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused - does this not work currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw an exception if using an expression instead of a model value, this change will allow for both implementations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have commented, I read the related issue and understood.

isOpenExp.assign(ttScope.origScope, ttScope.isOpen);
}

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

// First things first: we don't show it anymore.
ttScope.isOpen = false;
if (isOpenExp) {
if (isOpenExp && angular.isFunction(isOpenExp.assign)) {
isOpenExp.assign(ttScope.origScope, ttScope.isOpen);
}