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

Commit c534cb4

Browse files
rmckeelwesleycho
authored andcommitted
feat(dropdown): remove $locationChangeSuccess listener
- Remove listener for $locationChangeSuccess event BREAKING CHANGE: The dropdown no longer will remain open on $locationChangeSuccess with autoclose set to disabled. Implement this logic inside app along with usage of isOpen two-way binding if this functionality is desired. Closes #5648 Closes #5680
1 parent 45165ba commit c534cb4

File tree

3 files changed

+1
-51
lines changed

3 files changed

+1
-51
lines changed

src/dropdown/docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Each of these parts need to be used as attribute directives.
1414
_(Default: `always`)_ -
1515
Controls the behavior of the menu when clicked.
1616
* `always` - Automatically closes the dropdown when any of its elements is clicked.
17-
* `disabled` - Disables the auto close. You can control it manually with `is-open`. It still gets closed if the toggle is clicked, `esc` is pressed or another dropdown is open. It also won't be closed on `$locationchangeSuccess`.
17+
* `disabled` - Disables the auto close. You can control it manually with `is-open`. It still gets closed if the toggle is clicked, `esc` is pressed or another dropdown is open.
1818
* `outsideClick` - Closes the dropdown automatically only when the user clicks any element outside the dropdown.
1919

2020
* `dropdown-append-to`

src/dropdown/dropdown.js

-6
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
268268
setIsOpen($scope, isOpen);
269269
}
270270
});
271-
272-
$scope.$on('$locationChangeSuccess', function() {
273-
if (scope.getAutoClose() !== 'disabled') {
274-
scope.isOpen = false;
275-
}
276-
});
277271
}])
278272

279273
.directive('uibDropdown', function() {

src/dropdown/test/dropdown.spec.js

-44
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ describe('uib-dropdown', function() {
8888
expect(element).toHaveClass(dropdownConfig.openClass);
8989
});
9090

91-
it('should close on $location change', function() {
92-
clickDropdownToggle();
93-
expect(element).toHaveClass(dropdownConfig.openClass);
94-
$rootScope.$broadcast('$locationChangeSuccess');
95-
$rootScope.$apply();
96-
expect(element).not.toHaveClass(dropdownConfig.openClass);
97-
});
98-
9991
it('should only allow one dropdown to be open at once', function() {
10092
var elm1 = dropdown();
10193
var elm2 = dropdown();
@@ -279,32 +271,6 @@ describe('uib-dropdown', function() {
279271
});
280272
});
281273

282-
describe('integration with $location URL rewriting', function() {
283-
function dropdown() {
284-
// Simulate URL rewriting behavior
285-
$document.on('click', 'a[href="#something"]', function() {
286-
$rootScope.$broadcast('$locationChangeSuccess');
287-
$rootScope.$apply();
288-
});
289-
290-
return $compile('<li uib-dropdown><a href uib-dropdown-toggle></a>' +
291-
'<ul><li><a href="#something">Hello</a></li></ul></li>')($rootScope);
292-
}
293-
294-
beforeEach(function() {
295-
element = dropdown();
296-
});
297-
298-
it('should close without errors on $location change', function() {
299-
$document.find('body').append(element);
300-
clickDropdownToggle();
301-
expect(element).toHaveClass(dropdownConfig.openClass);
302-
var optionEl = element.find('ul > li').eq(0).find('a').eq(0);
303-
optionEl.click();
304-
expect(element).not.toHaveClass(dropdownConfig.openClass);
305-
});
306-
});
307-
308274
describe('using is-open', function() {
309275
describe('with uib-dropdown-toggle', function() {
310276
beforeEach(function() {
@@ -521,16 +487,6 @@ describe('uib-dropdown', function() {
521487
expect(elm1).not.toHaveClass(dropdownConfig.openClass);
522488
expect(elm2).toHaveClass(dropdownConfig.openClass);
523489
});
524-
525-
it('should not close on $locationChangeSuccess if auto-close="disabled"', function() {
526-
var elm1 = dropdown('disabled');
527-
expect(elm1).not.toHaveClass(dropdownConfig.openClass);
528-
clickDropdownToggle(elm1);
529-
expect(elm1).toHaveClass(dropdownConfig.openClass);
530-
$rootScope.$broadcast('$locationChangeSuccess');
531-
$rootScope.$digest();
532-
expect(elm1).toHaveClass(dropdownConfig.openClass);
533-
});
534490
});
535491

536492
describe('outsideClick', function() {

0 commit comments

Comments
 (0)