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

Commit 004dd1d

Browse files
committedApr 11, 2014
fix(dropdown): do not call on-toggle initially
Closes #2021
1 parent 4c76a85 commit 004dd1d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
 

‎src/dropdown/dropdown.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ angular.module('ui.bootstrap.dropdown', [])
7878
}
7979
};
8080

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

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

9191
setIsOpen($scope, isOpen);
92-
toggleInvoker($scope, { open: !!isOpen });
92+
if (angular.isDefined(wasOpen) && isOpen !== wasOpen) {
93+
toggleInvoker($scope, { open: !!isOpen });
94+
}
9395
});
9496

9597
$scope.$on('$locationChangeSuccess', function() {

‎src/dropdown/test/dropdown.spec.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,18 @@ describe('dropdownToggle', function() {
212212
describe('`on-toggle`', function() {
213213
beforeEach(function() {
214214
$rootScope.toggleHandler = jasmine.createSpy('toggleHandler');
215-
element = $compile('<li class="dropdown" on-toggle="toggleHandler(open)"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>')($rootScope);
215+
$rootScope.isopen = false;
216+
element = $compile('<li class="dropdown" on-toggle="toggleHandler(open)" is-open="isopen"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>')($rootScope);
216217
$rootScope.$digest();
217218
});
218219

219-
it('should be called initially', function() {
220-
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
220+
it('should not have been called initially', function() {
221+
expect($rootScope.toggleHandler).not.toHaveBeenCalled();
221222
});
222223

223224
it('should call it correctly when toggles', function() {
224-
clickDropdownToggle();
225+
$rootScope.isopen = true;
226+
$rootScope.$digest();
225227
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
226228

227229
clickDropdownToggle();
@@ -237,8 +239,8 @@ describe('dropdownToggle', function() {
237239
$rootScope.$digest();
238240
});
239241

240-
it('should be called initially with true', function() {
241-
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
242+
it('should not have been called initially', function() {
243+
expect($rootScope.toggleHandler).not.toHaveBeenCalled();
242244
});
243245

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

0 commit comments

Comments
 (0)
This repository has been archived.