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

fix(collapse): set initial state to avoid animation #5075

Closed
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
6 changes: 6 additions & 0 deletions src/collapse/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ angular.module('ui.bootstrap.collapse', [])
var $animateCss = $injector.has('$animateCss') ? $injector.get('$animateCss') : null;
return {
link: function(scope, element, attrs) {
if (!scope.$eval(attrs.uibCollapse)) {
element.addClass('in')
.addClass('collapse')
.css({height: 'auto'});
}

function expand() {
element.removeClass('collapse')
.addClass('collapsing')
Expand Down
12 changes: 10 additions & 2 deletions src/collapse/test/collapse.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('collapse directive', function() {
var element, scope, $compile, $animate;
var element, compileFn, scope, $compile, $animate;

beforeEach(module('ui.bootstrap.collapse'));
beforeEach(module('ngAnimateMock'));
Expand All @@ -10,7 +10,8 @@ describe('collapse directive', function() {
}));

beforeEach(function() {
element = $compile('<div uib-collapse="isCollapsed">Some Content</div>')(scope);
element = angular.element('<div uib-collapse="isCollapsed">Some Content</div>');
compileFn = $compile(element);
angular.element(document.body).append(element);
});

Expand All @@ -20,12 +21,14 @@ describe('collapse directive', function() {

it('should be hidden on initialization if isCollapsed = true', function() {
scope.isCollapsed = true;
compileFn(scope);
scope.$digest();
expect(element.height()).toBe(0);
});

it('should collapse if isCollapsed = true on subsequent use', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
scope.isCollapsed = true;
Expand All @@ -36,13 +39,15 @@ describe('collapse directive', function() {

it('should be shown on initialization if isCollapsed = false', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
expect(element.height()).not.toBe(0);
});

it('should expand if isCollapsed = false on subsequent use', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
scope.isCollapsed = true;
Expand All @@ -56,6 +61,7 @@ describe('collapse directive', function() {

it('should expand if isCollapsed = true on subsequent uses', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
scope.isCollapsed = true;
Expand All @@ -72,6 +78,7 @@ describe('collapse directive', function() {

it('should change aria-expanded attribute', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
expect(element.attr('aria-expanded')).toBe('true');
Expand All @@ -84,6 +91,7 @@ describe('collapse directive', function() {

it('should change aria-hidden attribute', function() {
scope.isCollapsed = false;
compileFn(scope);
scope.$digest();
$animate.flush();
expect(element.attr('aria-hidden')).toBe('false');
Expand Down