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

Commit ef09517

Browse files
committed
fix(dropdown): compatibility with $location url rewriting
Fixes #2343
1 parent f15bfcf commit ef09517

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/dropdown/dropdown.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ angular.module('ui.bootstrap.dropdown', [])
2929
};
3030

3131
var closeDropdown = function( evt ) {
32+
// This method may still be called during the same mouse event that
33+
// unbound this event handler. So check openScope before proceeding.
34+
if (!openScope) { return; }
35+
3236
var toggleElement = openScope.getToggleElement();
3337
if ( evt && toggleElement && toggleElement[0].contains(evt.target) ) {
3438
return;

src/dropdown/test/dropdown.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,33 @@ describe('dropdownToggle', function() {
168168
});
169169
});
170170

171+
describe('integration with $location URL rewriting', function() {
172+
function dropdown() {
173+
174+
// Simulate URL rewriting behavior
175+
$document.on('click', 'a[href="#something"]', function () {
176+
$rootScope.$broadcast('$locationChangeSuccess');
177+
$rootScope.$apply();
178+
});
179+
180+
return $compile('<li dropdown><a href dropdown-toggle></a>' +
181+
'<ul><li><a href="#something">Hello</a></li></ul></li>')($rootScope);
182+
}
183+
184+
beforeEach(function() {
185+
element = dropdown();
186+
});
187+
188+
it('should close without errors on $location change', function() {
189+
$document.find('body').append(element);
190+
clickDropdownToggle();
191+
expect(element.hasClass('open')).toBe(true);
192+
var optionEl = element.find('ul > li').eq(0).find('a').eq(0);
193+
optionEl.click();
194+
expect(element.hasClass('open')).toBe(false);
195+
});
196+
});
197+
171198
describe('without trigger', function() {
172199
beforeEach(function() {
173200
$rootScope.isopen = true;

0 commit comments

Comments
 (0)