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

Commit 5db9c39

Browse files
committed
fix($animate): ensure hidden elements with ngShow/ngHide stay hidden during animations
Prior to this fix if an element that contained ng-show or ng-hide was in its hidden state then any other animation run on the same element would cause the animation to appear despite the element itself already being hidden. This patch ensures that NO animations are visible even if the element is set as hidden. Closes #9103
1 parent 44108d7 commit 5db9c39

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

css/angular.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak],
44
.ng-cloak, .x-ng-cloak,
5-
.ng-hide:not(.ng-animate) {
5+
.ng-hide:not(.ng-hide-animate) {
66
display: none !important;
77
}
88

src/ngMock/angular-mocks.js

+1
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
809809
animate.queue.push({
810810
event : method,
811811
element : arguments[0],
812+
options : arguments[arguments.length-1],
812813
args : arguments
813814
});
814815
return $delegate[method].apply($delegate, arguments);

test/ng/directive/ngShowHideSpec.js

+44
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ describe('ngShow / ngHide animations', function() {
156156
expect(item.element.text()).toBe('data');
157157
expect(item.element).toBeHidden();
158158
}));
159+
160+
it('should apply the temporary `.ng-hide-animate` class to the element',
161+
inject(function($compile, $rootScope, $animate) {
162+
163+
var item;
164+
var $scope = $rootScope.$new();
165+
$scope.on = false;
166+
element = $compile(html(
167+
'<div class="show-hide" ng-show="on">data</div>'
168+
))($scope);
169+
$scope.$digest();
170+
171+
item = $animate.queue.shift();
172+
expect(item.event).toEqual('addClass');
173+
expect(item.options).toEqual('ng-hide-animate');
174+
175+
$scope.on = true;
176+
$scope.$digest();
177+
item = $animate.queue.shift();
178+
expect(item.event).toEqual('removeClass');
179+
expect(item.options).toEqual('ng-hide-animate');
180+
}));
159181
});
160182

161183
describe('ngHide', function() {
@@ -181,5 +203,27 @@ describe('ngShow / ngHide animations', function() {
181203
expect(item.element.text()).toBe('datum');
182204
expect(item.element).toBeShown();
183205
}));
206+
207+
it('should apply the temporary `.ng-hide-animate` class to the element',
208+
inject(function($compile, $rootScope, $animate) {
209+
210+
var item;
211+
var $scope = $rootScope.$new();
212+
$scope.on = false;
213+
element = $compile(html(
214+
'<div class="show-hide" ng-hide="on">data</div>'
215+
))($scope);
216+
$scope.$digest();
217+
218+
item = $animate.queue.shift();
219+
expect(item.event).toEqual('removeClass');
220+
expect(item.options).toEqual('ng-hide-animate');
221+
222+
$scope.on = true;
223+
$scope.$digest();
224+
item = $animate.queue.shift();
225+
expect(item.event).toEqual('addClass');
226+
expect(item.options).toEqual('ng-hide-animate');
227+
}));
184228
});
185229
});

0 commit comments

Comments
 (0)