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

Commit 054341b

Browse files
Sneha Jainwesleycho
Sneha Jain
authored andcommitted
fix(dropdown): call toggle after animation
- Change to call toggle after animation completes Closes #3513 Closes #3655 Fixes #3511
1 parent b72efed commit 054341b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: src/dropdown/dropdown.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
171171
});
172172
}
173173

174-
$animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass);
174+
$animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass).then(function() {
175+
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
176+
toggleInvoker($scope, { open: !!isOpen });
177+
}
178+
});
175179

176180
if ( isOpen ) {
177181
if (self.dropdownMenuTemplateUrl) {
@@ -202,9 +206,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
202206
}
203207

204208
setIsOpen($scope, isOpen);
205-
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
206-
toggleInvoker($scope, { open: !!isOpen });
207-
}
208209
});
209210

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

Diff for: src/dropdown/test/dropdown.spec.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
describe('dropdownToggle', function() {
2-
var $compile, $rootScope, $document, $templateCache, dropdownConfig, element;
2+
var $compile, $rootScope, $document, $templateCache, dropdownConfig, element, $browser;
33

44
beforeEach(module('ui.bootstrap.dropdown'));
55

6-
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_, _dropdownConfig_) {
6+
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_, _dropdownConfig_, _$browser_) {
77
$compile = _$compile_;
88
$rootScope = _$rootScope_;
99
$document = _$document_;
1010
$templateCache = _$templateCache_;
1111
dropdownConfig = _dropdownConfig_;
12+
$browser = _$browser_;
1213
}));
1314

1415
afterEach(function() {
@@ -322,9 +323,11 @@ describe('dropdownToggle', function() {
322323
it('should call it correctly when toggles', function() {
323324
$rootScope.isopen = true;
324325
$rootScope.$digest();
326+
$browser.defer.flush();
325327
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
326328

327329
clickDropdownToggle();
330+
$browser.defer.flush();
328331
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
329332
});
330333
});
@@ -338,16 +341,19 @@ describe('dropdownToggle', function() {
338341
});
339342

340343
it('should not have been called initially', function() {
344+
$browser.defer.flush();
341345
expect($rootScope.toggleHandler).not.toHaveBeenCalled();
342346
});
343347

344348
it('should call it correctly when toggles', function() {
345349
$rootScope.isopen = false;
346350
$rootScope.$digest();
351+
$browser.defer.flush();
347352
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
348353

349354
$rootScope.isopen = true;
350355
$rootScope.$digest();
356+
$browser.defer.flush();
351357
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
352358
});
353359
});
@@ -360,14 +366,17 @@ describe('dropdownToggle', function() {
360366
});
361367

362368
it('should not have been called initially', function() {
369+
$browser.defer.flush();
363370
expect($rootScope.toggleHandler).not.toHaveBeenCalled();
364371
});
365372

366373
it('should call it when clicked', function() {
367374
clickDropdownToggle();
375+
$browser.defer.flush();
368376
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
369377

370378
clickDropdownToggle();
379+
$browser.defer.flush();
371380
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
372381
});
373382
});

0 commit comments

Comments
 (0)