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

Commit

Permalink
fix(dropdown): do not call on-toggle initially
Browse files Browse the repository at this point in the history
Closes #2021
  • Loading branch information
bekos committed Apr 11, 2014
1 parent 4c76a85 commit 004dd1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/dropdown/dropdown.js
Expand Up @@ -78,7 +78,7 @@ angular.module('ui.bootstrap.dropdown', [])
}
};

scope.$watch('isOpen', function( isOpen ) {
scope.$watch('isOpen', function( isOpen, wasOpen ) {
$animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass);

if ( isOpen ) {
Expand All @@ -89,7 +89,9 @@ angular.module('ui.bootstrap.dropdown', [])
}

setIsOpen($scope, isOpen);
toggleInvoker($scope, { open: !!isOpen });
if (angular.isDefined(wasOpen) && isOpen !== wasOpen) {
toggleInvoker($scope, { open: !!isOpen });
}
});

$scope.$on('$locationChangeSuccess', function() {
Expand Down
14 changes: 8 additions & 6 deletions src/dropdown/test/dropdown.spec.js
Expand Up @@ -212,16 +212,18 @@ describe('dropdownToggle', function() {
describe('`on-toggle`', 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.isopen = false;
element = $compile('<li class="dropdown" on-toggle="toggleHandler(open)" is-open="isopen"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>')($rootScope);
$rootScope.$digest();
});

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

it('should call it correctly when toggles', function() {
clickDropdownToggle();
$rootScope.isopen = true;
$rootScope.$digest();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);

clickDropdownToggle();
Expand All @@ -237,8 +239,8 @@ describe('dropdownToggle', function() {
$rootScope.$digest();
});

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

it('should call it correctly when toggles', function() {
Expand Down

0 comments on commit 004dd1d

Please sign in to comment.