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

Commit f5b357f

Browse files
matthias-ccriwesleycho
authored andcommitted
fix(tooltip): unbind keypress listener on hide
- Unbind listener on hide to fix memory leak Closes #6423 Fixes #6405
1 parent 761db7b commit f5b357f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/tooltip/tooltip.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
496496
}
497497
}
498498

499+
// KeyboardEvent handler to hide the tooltip on Escape key press
500+
function hideOnEscapeKey(e) {
501+
if (e.which === 27) {
502+
hideTooltipBind();
503+
}
504+
}
505+
499506
var unregisterTriggers = function() {
500507
triggers.show.forEach(function(trigger) {
501508
if (trigger === 'outsideClick') {
@@ -504,6 +511,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
504511
element.off(trigger, showTooltipBind);
505512
element.off(trigger, toggleTooltipBind);
506513
}
514+
element.off('keypress', hideOnEscapeKey);
507515
});
508516
triggers.hide.forEach(function(trigger) {
509517
if (trigger === 'outsideClick') {
@@ -543,12 +551,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
543551
element.on(trigger, showTooltipBind);
544552
element.on(triggers.hide[idx], hideTooltipBind);
545553
}
546-
547-
element.on('keypress', function(e) {
548-
if (e.which === 27) {
549-
hideTooltipBind();
550-
}
551-
});
554+
element.on('keypress', hideOnEscapeKey);
552555
});
553556
}
554557
}

0 commit comments

Comments
 (0)