@@ -21,7 +21,20 @@ angular.module('ui.bootstrap.collapse',['ui.bootstrap.transition'])
21
21
link : function ( scope , element , attrs ) {
22
22
23
23
var isCollapsed ;
24
-
24
+ var initialAnimSkip = true ;
25
+ scope . $watch ( function ( ) { return element [ 0 ] . scrollHeight ; } , function ( value ) {
26
+ //The listener is called when scollHeight changes
27
+ //It actually does on 2 scenarios:
28
+ // 1. Parent is set to display none
29
+ // 2. angular bindings inside are resolved
30
+ //When we have a change of scrollHeight we are setting again the correct height if the group is opened
31
+ if ( element [ 0 ] . scrollHeight !== 0 ) {
32
+ if ( ! isCollapsed ) {
33
+ fixUpHeight ( scope , element , element [ 0 ] . scrollHeight + 'px' ) ;
34
+ }
35
+ }
36
+ } ) ;
37
+
25
38
scope . $watch ( attrs . collapse , function ( value ) {
26
39
if ( value ) {
27
40
collapse ( ) ;
@@ -45,21 +58,33 @@ angular.module('ui.bootstrap.collapse',['ui.bootstrap.transition'])
45
58
} ;
46
59
47
60
var expand = function ( ) {
48
- doTransition ( { height : element [ 0 ] . scrollHeight + 'px' } )
49
- . then ( function ( ) {
50
- // This check ensures that we don't accidentally update the height if the user has closed
51
- // the group while the animation was still running
61
+ if ( initialAnimSkip ) {
62
+ initialAnimSkip = false ;
52
63
if ( ! isCollapsed ) {
53
64
fixUpHeight ( scope , element , 'auto' ) ;
54
65
}
55
- } ) ;
66
+ } else {
67
+ doTransition ( { height : element [ 0 ] . scrollHeight + 'px' } )
68
+ . then ( function ( ) {
69
+ // This check ensures that we don't accidentally update the height if the user has closed
70
+ // the group while the animation was still running
71
+ if ( ! isCollapsed ) {
72
+ fixUpHeight ( scope , element , 'auto' ) ;
73
+ }
74
+ } ) ;
75
+ }
56
76
isCollapsed = false ;
57
77
} ;
58
78
59
79
var collapse = function ( ) {
60
80
isCollapsed = true ;
61
- fixUpHeight ( scope , element , element [ 0 ] . scrollHeight + 'px' ) ;
62
- doTransition ( { 'height' :'0' } ) ;
81
+ if ( initialAnimSkip ) {
82
+ initialAnimSkip = false ;
83
+ fixUpHeight ( scope , element , 0 ) ;
84
+ } else {
85
+ fixUpHeight ( scope , element , element [ 0 ] . scrollHeight + 'px' ) ;
86
+ doTransition ( { 'height' :'0' } ) ;
87
+ }
63
88
} ;
64
89
}
65
90
} ;
0 commit comments