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

Commit

Permalink
fix(dropdown): do not close on $locationChangeSuccess
Browse files Browse the repository at this point in the history
Behaviour only triggers when `auto-close=disabled`

Closes #3683, #3704
  • Loading branch information
CloudNiner authored and Robin van Baalen committed Jun 3, 2015
1 parent 9247f15 commit e5a1e88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/dropdown/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 3 additions & 1 deletion src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit e5a1e88

Please sign in to comment.