diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index 78644af28d..40d2bbe0c1 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -50,6 +50,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) } openScope.isOpen = false; + openScope.focusToggleElement(); if (!$rootScope.$$phase) { openScope.$apply(); diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 825c42fbfe..197d148580 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -220,12 +220,28 @@ describe('uib-dropdown', function() { beforeEach(function() { element = dropdown(); + $document.find('body').append(element); + }); + + afterEach(function() { + element.remove(); }); it('adds the menu to the body', function() { expect($document.find('#dropdown-menu').parent()[0]).toBe($document.find('body')[0]); }); + it('focuses the dropdown element on close', function() { + var toggle = element.find('[uib-dropdown-toggle]'); + var menu = $document.find('#dropdown-menu a'); + toggle.trigger('click'); + menu.focus(); + + menu.trigger('click'); + + expect(document.activeElement).toBe(toggle[0]); + }); + it('removes the menu when the dropdown is removed', function() { element.remove(); $rootScope.$digest(); @@ -268,6 +284,17 @@ describe('uib-dropdown', function() { expect(container).not.toHaveClass('uib-dropdown-open'); }); + it('focuses the dropdown element on close', function() { + var toggle = element.find('[uib-dropdown-toggle]'); + var menu = $document.find('#dropdown-menu a'); + toggle.trigger('click'); + menu.focus(); + + menu.trigger('click'); + + expect(document.activeElement).toBe(toggle[0]); + }); + it('removes the menu when the dropdown is removed', function() { element.remove(); $rootScope.$digest();