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

fix(dropdown): do not call on-toggle initially #2021

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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