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

fix(dropdown): Do not close on $locationChangeSuccess #3704

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});