diff --git a/src/dropdown/docs/readme.md b/src/dropdown/docs/readme.md index 02970d0a5f..47851ea1a3 100644 --- a/src/dropdown/docs/readme.md +++ b/src/dropdown/docs/readme.md @@ -10,5 +10,4 @@ By default the dropdown will automatically close if any of its elements is click * `always` - (Default) automatically closes the dropdown when any of its elements is clicked. * `outsideClick` - closes the dropdown automatically only when the user clicks any element outside the dropdown. - * `disabled` - disables the auto close. You can then control the open/close status of the dropdown manually, by using `is-open`. Please notice that the dropdown will still close if the toggle is clicked, the `esc` key is pressed or another dropdown is open. - + * `disabled` - disables the auto close. You can then control the open/close status of the dropdown manually, by using `is-open`. Please notice that the dropdown will still close if the toggle is clicked, the `esc` key is pressed or another dropdown is open. The dropdown will no longer close on `$locationChangeSuccess` events. diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index 8f03186160..de5cba6d8d 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -144,7 +144,9 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) }); $scope.$on('$locationChangeSuccess', function() { - scope.isOpen = false; + if (scope.getAutoClose() !== 'disabled') { + scope.isOpen = false; + } }); $scope.$on('$destroy', function() { diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 047ca09720..75ab9fa7c2 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -432,5 +432,15 @@ describe('dropdownToggle', function() { expect(elm1.hasClass(dropdownConfig.openClass)).toBe(false); expect(elm2.hasClass(dropdownConfig.openClass)).toBe(true); }); + + it('should not close on $locationChangeSuccess if auto-close="disabled"', function () { + var elm1 = dropdown('disabled'); + expect(elm1.hasClass(dropdownConfig.openClass)).toBe(false); + clickDropdownToggle(elm1); + expect(elm1.hasClass(dropdownConfig.openClass)).toBe(true); + $rootScope.$broadcast('$locationChangeSuccess'); + $rootScope.$digest(); + expect(elm1.hasClass(dropdownConfig.openClass)).toBe(true); + }); }); });