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

Commit

Permalink
feat(dropdown): remove $locationChangeSuccess listener
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
rmckeel authored and wesleycho committed Mar 22, 2016
1 parent 45165ba commit c534cb4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 51 deletions.
2 changes: 1 addition & 1 deletion src/dropdown/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Each of these parts need to be used as attribute directives.
_(Default: `always`)_ -
Controls the behavior of the menu when clicked.
* `always` - Automatically closes the dropdown when any of its elements is clicked.
* `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`.
* `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.
* `outsideClick` - Closes the dropdown automatically only when the user clicks any element outside the dropdown.

* `dropdown-append-to`
Expand Down
6 changes: 0 additions & 6 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
setIsOpen($scope, isOpen);
}
});

$scope.$on('$locationChangeSuccess', function() {
if (scope.getAutoClose() !== 'disabled') {
scope.isOpen = false;
}
});
}])

.directive('uibDropdown', function() {
Expand Down
44 changes: 0 additions & 44 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ describe('uib-dropdown', function() {
expect(element).toHaveClass(dropdownConfig.openClass);
});

it('should close on $location change', function() {
clickDropdownToggle();
expect(element).toHaveClass(dropdownConfig.openClass);
$rootScope.$broadcast('$locationChangeSuccess');
$rootScope.$apply();
expect(element).not.toHaveClass(dropdownConfig.openClass);
});

it('should only allow one dropdown to be open at once', function() {
var elm1 = dropdown();
var elm2 = dropdown();
Expand Down Expand Up @@ -279,32 +271,6 @@ describe('uib-dropdown', function() {
});
});

describe('integration with $location URL rewriting', function() {
function dropdown() {
// Simulate URL rewriting behavior
$document.on('click', 'a[href="#something"]', function() {
$rootScope.$broadcast('$locationChangeSuccess');
$rootScope.$apply();
});

return $compile('<li uib-dropdown><a href uib-dropdown-toggle></a>' +
'<ul><li><a href="#something">Hello</a></li></ul></li>')($rootScope);
}

beforeEach(function() {
element = dropdown();
});

it('should close without errors on $location change', function() {
$document.find('body').append(element);
clickDropdownToggle();
expect(element).toHaveClass(dropdownConfig.openClass);
var optionEl = element.find('ul > li').eq(0).find('a').eq(0);
optionEl.click();
expect(element).not.toHaveClass(dropdownConfig.openClass);
});
});

describe('using is-open', function() {
describe('with uib-dropdown-toggle', function() {
beforeEach(function() {
Expand Down Expand Up @@ -521,16 +487,6 @@ describe('uib-dropdown', function() {
expect(elm1).not.toHaveClass(dropdownConfig.openClass);
expect(elm2).toHaveClass(dropdownConfig.openClass);
});

it('should not close on $locationChangeSuccess if auto-close="disabled"', function() {
var elm1 = dropdown('disabled');
expect(elm1).not.toHaveClass(dropdownConfig.openClass);
clickDropdownToggle(elm1);
expect(elm1).toHaveClass(dropdownConfig.openClass);
$rootScope.$broadcast('$locationChangeSuccess');
$rootScope.$digest();
expect(elm1).toHaveClass(dropdownConfig.openClass);
});
});

describe('outsideClick', function() {
Expand Down

0 comments on commit c534cb4

Please sign in to comment.