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

Commit

Permalink
fix(tooltip): unbind keypress listener on hide
Browse files Browse the repository at this point in the history
- Unbind listener on hide to fix memory leak

Closes #6423
Fixes #6405
  • Loading branch information
matthias-ccri authored and wesleycho committed Jan 23, 2017
1 parent 761db7b commit f5b357f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/tooltip/tooltip.js
Expand Up @@ -496,6 +496,13 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
}
}

// KeyboardEvent handler to hide the tooltip on Escape key press
function hideOnEscapeKey(e) {
if (e.which === 27) {
hideTooltipBind();
}
}

var unregisterTriggers = function() {
triggers.show.forEach(function(trigger) {
if (trigger === 'outsideClick') {
Expand All @@ -504,6 +511,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
element.off(trigger, showTooltipBind);
element.off(trigger, toggleTooltipBind);
}
element.off('keypress', hideOnEscapeKey);
});
triggers.hide.forEach(function(trigger) {
if (trigger === 'outsideClick') {
Expand Down Expand Up @@ -543,12 +551,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
element.on(trigger, showTooltipBind);
element.on(triggers.hide[idx], hideTooltipBind);
}

element.on('keypress', function(e) {
if (e.which === 27) {
hideTooltipBind();
}
});
element.on('keypress', hideOnEscapeKey);
});
}
}
Expand Down

0 comments on commit f5b357f

Please sign in to comment.