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

Commit 9ec7d40

Browse files
committed
refactor(accordion): use ngAnimate for animations
- Deprecate collapse module Consider removing it after transition module is deprecated as well.
1 parent 6bc6634 commit 9ec7d40

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

src/accordion/accordion.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
1+
angular.module('ui.bootstrap.accordion', [])
22

33
.constant('accordionConfig', {
44
closeOthers: true
@@ -129,4 +129,64 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
129129
});
130130
}
131131
};
132-
});
132+
})
133+
134+
/**
135+
* Animations based on addition and removal of `in` class
136+
* This requires the bootstrap classes to be present in order to take advantage
137+
* of the animation classes.
138+
*/
139+
.animation('.panel-collapse', function () {
140+
return {
141+
beforeAddClass: function (element, className, done) {
142+
if (className == 'in') {
143+
element
144+
.removeClass('collapse')
145+
.addClass('collapsing')
146+
.css({height: '0'});
147+
}
148+
done();
149+
},
150+
addClass: function (element, className, done) {
151+
if (className == 'in') {
152+
element
153+
.css({height: element[0].scrollHeight + 'px'})
154+
.removeClass('collapsing')
155+
// FIXME awaiting: https://github.com/angular/angular.js/pull/5984
156+
.on('$animate:close', function closeFn() {
157+
element
158+
.css({height: 'auto'});
159+
element.off('$animate:close', closeFn);
160+
});
161+
}
162+
done();
163+
},
164+
beforeRemoveClass: function (element, className, done) {
165+
if (className == 'in') {
166+
element
167+
// initially all panel collapse have the collapse class, this removal
168+
// prevents the animation from jumping to collapsed state
169+
.removeClass('collapse')
170+
.addClass('collapsing')
171+
.css({height: element[0].scrollHeight + 'px'});
172+
}
173+
done();
174+
},
175+
removeClass: function (element, className, done) {
176+
if (className == 'in') {
177+
element
178+
.css({height: '0'})
179+
.removeClass('collapsing')
180+
// FIXME awaiting: https://github.com/angular/angular.js/pull/5984
181+
.on('$animate:close', function closeFn() {
182+
element
183+
.addClass('collapse');
184+
element.off('$animate:close', closeFn);
185+
});
186+
}
187+
done();
188+
}
189+
};
190+
})
191+
192+
;

src/accordion/test/accordion.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ describe('accordion', function () {
265265
});
266266

267267
it('should have visible panel body when the group with isOpen set to true', function () {
268-
expect(findGroupBody(0)[0].clientHeight).not.toBe(0);
269-
expect(findGroupBody(1)[0].clientHeight).toBe(0);
268+
expect(findGroupBody(0)).toHaveClass('in');
269+
expect(findGroupBody(1)).not.toHaveClass('in');
270270
});
271271
});
272272

src/collapse/collapse.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @deprecated Switching over to using ngAnimate for animations
3+
*/
14
angular.module('ui.bootstrap.collapse', ['ui.bootstrap.transition'])
25

36
.directive('collapse', ['$transition', function ($transition) {

template/accordion/accordion-group.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h4 class="panel-title">
44
<a class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
55
</h4>
66
</div>
7-
<div class="panel-collapse" collapse="!isOpen">
7+
<div class="panel-collapse collapse" ng-class="{in: isOpen}">
88
<div class="panel-body" ng-transclude></div>
99
</div>
1010
</div>

0 commit comments

Comments
 (0)