From 12c527afb333d62044bfac194cde05ec66afbded Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Mon, 3 Aug 2015 20:50:55 -0700 Subject: [PATCH] fix(tooltip): prevent opening when `tooltipPopupDelay` is present - Cancel the timeout when `tooltipPopupDelay` is present and the element with the tooltip directive becomes disabled Closes #4098 Fixes #3611 --- src/tooltip/test/tooltip.spec.js | 15 ++++++++++++++- src/tooltip/tooltip.js | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index c10b147d96..578b95ac6b 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -260,7 +260,7 @@ describe('tooltip', function() { beforeEach(inject(function ($compile) { scope.delay='1000'; elm = $compile(angular.element( - 'Selector Text' + 'Selector Text' ))(scope); elmScope = elm.scope(); tooltipScope = elmScope.$$childTail; @@ -293,6 +293,19 @@ describe('tooltip', function() { expect(tooltipScope.isOpen).toBe(true); }); + it('should not open if disabled is present', inject(function($timeout) { + elm.trigger('mouseenter'); + expect(tooltipScope.isOpen).toBe(false); + + $timeout.flush(500); + expect(tooltipScope.isOpen).toBe(false); + elmScope.disabled = true; + elmScope.$digest(); + + $timeout.flush(); + expect(tooltipScope.isOpen).toBe(false); + })); + }); describe( 'with a trigger attribute', function() { diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index dde89c4b46..2f1a571e54 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -299,6 +299,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap } attrs.$observe( 'disabled', function ( val ) { + if (popupTimeout && val) { + $timeout.cancel(popupTimeout); + } + if (val && ttScope.isOpen ) { hide(); }