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

Commit

Permalink
fix(collapse): Avoids fixed height on collapse
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
SidhNor committed Feb 13, 2013
1 parent 897c2e4 commit ff5d119
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/collapse/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ angular.module('ui.bootstrap.collapse',['ui.bootstrap.transition'])
//When we have a change of scrollHeight we are setting again the correct height if the group is opened
if (element[0].scrollHeight !== 0) {
if (!isCollapsed) {
fixUpHeight(scope, element, element[0].scrollHeight + 'px');
if (initialAnimSkip) {
fixUpHeight(scope, element, element[0].scrollHeight + 'px');
} else {
fixUpHeight(scope, element, 'auto');
}
}
}
});
Expand Down
49 changes: 49 additions & 0 deletions src/collapse/test/collapse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,53 @@ describe('collapse directive', function () {
$timeout.flush();
expect(element.height()).not.toBe(0);
});

describe('dynamic content', function() {
beforeEach(function() {
element = angular.element('<div collapse="isCollapsed"><p>Initial content</p><div ng-show="exp">Additional content</div></div>');
$compile(element)(scope);
angular.element(document.body).append(element);
});

afterEach(function() {
element.remove();
});

it('should grow accordingly when content size inside collapse increases', function() {
scope.exp = false;
scope.isCollapsed = false;
scope.$digest();
var collapseHeight = element.height();
scope.exp = true;
scope.$digest();
expect(element.height()).toBeGreaterThan(collapseHeight);
});

it('should shrink accordingly when content size inside collapse decreases', function() {
scope.exp = true;
scope.isCollapsed = false;
scope.$digest();
var collapseHeight = element.height();
scope.exp = false;
scope.$digest();
expect(element.height()).toBeLessThan(collapseHeight);
});

it('should shrink accordingly when content size inside collapse decreases on subsequent use', function() {
scope.isCollapsed = false;
scope.exp = false;
scope.$digest();
scope.isCollapsed = true;
scope.$digest();
scope.isCollapsed = false;
scope.$digest();
$timeout.flush();
scope.exp = true;
scope.$digest();
var collapseHeight = element.height();
scope.exp = false;
scope.$digest();
expect(element.height()).toBeLessThan(collapseHeight);
});
});
});

0 comments on commit ff5d119

Please sign in to comment.