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

Commit e5a1e88

Browse files
CloudNinerRobin van Baalen
authored and
Robin van Baalen
committed
fix(dropdown): do not close on $locationChangeSuccess
Behaviour only triggers when `auto-close=disabled` Closes #3683, #3704
1 parent 9247f15 commit e5a1e88

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/dropdown/docs/readme.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ By default the dropdown will automatically close if any of its elements is click
1010

1111
* `always` - (Default) automatically closes the dropdown when any of its elements is clicked.
1212
* `outsideClick` - closes the dropdown automatically only when the user clicks any element outside the dropdown.
13-
* `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.
14-
13+
* `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.

src/dropdown/dropdown.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
144144
});
145145

146146
$scope.$on('$locationChangeSuccess', function() {
147-
scope.isOpen = false;
147+
if (scope.getAutoClose() !== 'disabled') {
148+
scope.isOpen = false;
149+
}
148150
});
149151

150152
$scope.$on('$destroy', function() {

src/dropdown/test/dropdown.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -432,5 +432,15 @@ describe('dropdownToggle', function() {
432432
expect(elm1.hasClass(dropdownConfig.openClass)).toBe(false);
433433
expect(elm2.hasClass(dropdownConfig.openClass)).toBe(true);
434434
});
435+
436+
it('should not close on $locationChangeSuccess if auto-close="disabled"', function () {
437+
var elm1 = dropdown('disabled');
438+
expect(elm1.hasClass(dropdownConfig.openClass)).toBe(false);
439+
clickDropdownToggle(elm1);
440+
expect(elm1.hasClass(dropdownConfig.openClass)).toBe(true);
441+
$rootScope.$broadcast('$locationChangeSuccess');
442+
$rootScope.$digest();
443+
expect(elm1.hasClass(dropdownConfig.openClass)).toBe(true);
444+
});
435445
});
436446
});

0 commit comments

Comments
 (0)