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

Commit

Permalink
fix(dropdown): compatibility with $location url rewriting
Browse files Browse the repository at this point in the history
Fixes #2343
  • Loading branch information
chrisirhc committed Oct 1, 2014
1 parent f15bfcf commit ef09517
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ angular.module('ui.bootstrap.dropdown', [])
};

var closeDropdown = function( evt ) {
// This method may still be called during the same mouse event that
// unbound this event handler. So check openScope before proceeding.
if (!openScope) { return; }

var toggleElement = openScope.getToggleElement();
if ( evt && toggleElement && toggleElement[0].contains(evt.target) ) {
return;
Expand Down
27 changes: 27 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ describe('dropdownToggle', 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 dropdown><a href 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.hasClass('open')).toBe(true);
var optionEl = element.find('ul > li').eq(0).find('a').eq(0);
optionEl.click();
expect(element.hasClass('open')).toBe(false);
});
});

describe('without trigger', function() {
beforeEach(function() {
$rootScope.isopen = true;
Expand Down

1 comment on commit ef09517

@khoden
Copy link

@khoden khoden commented on ef09517 Nov 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This fix #2868 issue)

Please sign in to comment.