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

Dropdown toggle called after the animation #3655

Closed
wants to merge 3 commits 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
9 changes: 5 additions & 4 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
});
}

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

if ( isOpen ) {
scope.focusToggleElement();
Expand All @@ -138,9 +142,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
}

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

$scope.$on('$locationChangeSuccess', function() {
Expand Down
13 changes: 11 additions & 2 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
describe('dropdownToggle', function() {
var $compile, $rootScope, $document, dropdownConfig, element;
var $compile, $rootScope, $document, dropdownConfig, element, $browser;

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

beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _dropdownConfig_) {
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _dropdownConfig_, _$browser_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$document = _$document_;
dropdownConfig = _dropdownConfig_;
$browser = _$browser_;
}));

afterEach(function() {
Expand Down Expand Up @@ -297,9 +298,11 @@ describe('dropdownToggle', function() {
it('should call it correctly when toggles', function() {
$rootScope.isopen = true;
$rootScope.$digest();
$browser.defer.flush();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);

clickDropdownToggle();
$browser.defer.flush();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
});
});
Expand All @@ -313,16 +316,19 @@ describe('dropdownToggle', function() {
});

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

it('should call it correctly when toggles', function() {
$rootScope.isopen = false;
$rootScope.$digest();
$browser.defer.flush();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);

$rootScope.isopen = true;
$rootScope.$digest();
$browser.defer.flush();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(true);
});
});
Expand All @@ -335,14 +341,17 @@ describe('dropdownToggle', function() {
});

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

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

clickDropdownToggle();
$browser.defer.flush();
expect($rootScope.toggleHandler).toHaveBeenCalledWith(false);
});
});
Expand Down