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

fix(dropdown): use $animate for adding and removing classes #1644

Closed
wants to merge 2 commits into from
Closed
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: 7 additions & 2 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ angular.module('ui.bootstrap.dropdown', [])
};
}])

.controller('DropdownController', ['$scope', '$attrs', 'dropdownConfig', 'dropdownService', function($scope, $attrs, dropdownConfig, dropdownService) {
.controller('DropdownController', ['$scope', '$attrs', 'dropdownConfig', 'dropdownService','$animate', function($scope, $attrs, dropdownConfig, dropdownService, $animate) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a space after the comma at ,'$anim.

var self = this, openClass = dropdownConfig.openClass;

this.init = function( element ) {
Expand All @@ -54,7 +54,12 @@ angular.module('ui.bootstrap.dropdown', [])
};

$scope.$watch('isOpen', function( value ) {
self.$element.toggleClass( openClass, value );
if (value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already an if clause for value. No need to add a new one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines can actually be shortened to:

$animate[value ? 'addClass' : 'removeClass'](self.$element, openClass);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$animate should have a promise, and the code after that should be inside the resolved function. Else the toggle function would be called before the dropdown is opened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request is closed as I see (it was created looong time ago).

$animate.addClass(self.$element, openClass);
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else should be in the same line as the closing braces of the if (} else {).

$animate.removeClass(self.$element, openClass);
}

if ( value ) {
dropdownService.open( $scope );
Expand Down