diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index e8e9d068e8..bbbed52324 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -224,6 +224,20 @@ describe('tooltip', function() { trigger(elm, 'mouseleave'); }); + it('should close when escape is hit while open', function() { + expect(tooltipScope.isOpen).toBe(false); + + trigger(elm, 'mouseenter'); + + expect(tooltipScope.isOpen).toBe(true); + + var event = $.Event('keypress'); + event.which = 27; + elm.trigger(event); + + expect(tooltipScope.isOpen).toBe(false); + }); + describe('with specified enable expression', function() { beforeEach(inject(function($compile) { scope.enable = false; diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 864d861afc..745ff619b2 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -406,6 +406,12 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position']) element[0].addEventListener(trigger, showTooltipBind); element[0].addEventListener(triggers.hide[idx], hideTooltipBind); } + + element.on('keypress', function(e) { + if (e.which === 27) { + hideTooltipBind(); + } + }); }); } }