Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngAnimate): allow removal of class that is scheduled to be added … #14760

Merged
merged 1 commit into from
Jun 22, 2016
Merged
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
4 changes: 2 additions & 2 deletions src/ngAnimate/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ function resolveElementClasses(existing, toAdd, toRemove) {
var prop, allow;
if (val === ADD_CLASS) {
prop = 'addClass';
allow = !existing[klass];
allow = !existing[klass] || existing[klass + REMOVE_CLASS_SUFFIX];
} else if (val === REMOVE_CLASS) {
prop = 'removeClass';
allow = existing[klass];
allow = existing[klass] || existing[klass + ADD_CLASS_SUFFIX];
}
if (allow) {
if (classes[prop].length) {
Expand Down
45 changes: 45 additions & 0 deletions test/ngAnimate/integrationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,51 @@ describe('ngAnimate integration tests', function() {
expect(doneHandler).toHaveBeenCalled();
}));

it('should remove a class that is currently being added by a running animation when another class is added in before in the same digest',
inject(function($animate, $rootScope, $$rAF, $document, $rootElement) {

jqLite($document[0].body).append($rootElement);
element = jqLite('<div></div>');
$rootElement.append(element);

var runner = $animate.addClass(element, 'red');

$rootScope.$digest();

$animate.addClass(element, 'blue');
$animate.removeClass(element, 'red');
$rootScope.$digest();

$$rAF.flush();

expect(element).not.toHaveClass('red');
expect(element).toHaveClass('blue');
}));


it('should add a class that is currently being removed by a running animation when another class is removed before in the same digest',
inject(function($animate, $rootScope, $$rAF, $document, $rootElement) {

jqLite($document[0].body).append($rootElement);
element = jqLite('<div></div>');
$rootElement.append(element);
element.addClass('red blue');

var runner = $animate.removeClass(element, 'red');

$rootScope.$digest();

$animate.removeClass(element, 'blue');
$animate.addClass(element, 'red');
$rootScope.$digest();

$$rAF.flush();

expect(element).not.toHaveClass('blue');
expect(element).toHaveClass('red');
}));


describe('CSS animations', function() {
if (!browserSupportsCssAnimations()) return;

Expand Down