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

Commit

Permalink
fix(dropdown): ensure on-toggle works when is-open is not used
Browse files Browse the repository at this point in the history
This fixes an issue where on-toggle doesn't get called on the first
click if the is-open attribute is not used.

Closes #2121
  • Loading branch information
Jose Martinez authored and pkozlowski-opensource committed May 1, 2014
1 parent cc07cdd commit 06ad3bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ angular.module('ui.bootstrap.dropdown', [])
}

setIsOpen($scope, isOpen);
if (angular.isDefined(wasOpen) && isOpen !== wasOpen) {
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
toggleInvoker($scope, { open: !!isOpen });
}
});
Expand Down
20 changes: 20 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,24 @@ describe('dropdownToggle', function() {
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
});
});

describe('`on-toggle` without is-open', function() {
beforeEach(function() {
$rootScope.toggleHandler = jasmine.createSpy('toggleHandler');
element = $compile('<li class="dropdown" on-toggle="toggleHandler(open)"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>')($rootScope);
$rootScope.$digest();
});

it('should not have been called initially', function() {
expect($rootScope.toggleHandler).not.toHaveBeenCalled();
});

it('should call it when clicked', function() {
clickDropdownToggle();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);

clickDropdownToggle();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
});
});
});

0 comments on commit 06ad3bd

Please sign in to comment.