@@ -11,13 +11,7 @@ import {
11
11
} from ' vue'
12
12
13
13
import { SAFE_STYLES , VISUALLY_HIDDEN , AUTO_DUR_VAR , FALLBACK_DURATION } from ' ./constants'
14
- import {
15
- getTransitionProp ,
16
- getComputedHeight ,
17
- getHeightProp ,
18
- getAutoDuration ,
19
- isReducedOrDisabled ,
20
- } from ' ./utils'
14
+ import { getTransitionProp , getComputedHeight , getAutoDuration , isReducedOrDisabled } from ' ./utils'
21
15
22
16
export type TransitionState = ' expanding' | ' expanded' | ' collapsing' | ' collapsed'
23
17
@@ -104,6 +98,15 @@ const setAutoDuration = (newDuration: number) => (autoDuration.value = newDurati
104
98
105
99
const autoDurationVar = computed (() => ({ [AUTO_DUR_VAR ]: ` ${autoDuration .value }ms ` }))
106
100
101
+ /**
102
+ * In some edge cases, Collapse may have children elements that also expand
103
+ * their height while expanding.
104
+ *
105
+ * When this occurs, the 'scrollHeight' obtained on transition start will be lower than
106
+ * the same 'scrollHeight' obtained on transition end.
107
+ */
108
+ let transitionStartScrollHeight = NaN
109
+
107
110
function onExpanded() {
108
111
replaceStyles (SAFE_STYLES )
109
112
setState (' expanded' )
@@ -139,6 +142,8 @@ onMounted(() => {
139
142
watch (isExpanded , (isExpanding ) => {
140
143
if (! collapseRef .value ) return
141
144
145
+ transitionStartScrollHeight = NaN
146
+
142
147
if (isExpanding ) {
143
148
if (isReducedOrDisabled (collapseRef )) return onExpanded ()
144
149
@@ -168,9 +173,11 @@ watch(isExpanded, (isExpanding) => {
168
173
169
174
/** Set height to scrollHeight and trigger the transition. */
170
175
176
+ transitionStartScrollHeight = collapseRef .value ! .scrollHeight
177
+
171
178
addStyles ({
172
- ... getHeightProp (collapseRef ),
173
179
... getTransitionProp (collapseRef ),
180
+ height: ` ${transitionStartScrollHeight }px ` ,
174
181
willChange: ' height' ,
175
182
})
176
183
})
@@ -189,7 +196,7 @@ watch(isExpanded, (isExpanding) => {
189
196
190
197
addStyles ({
191
198
... autoDurationVar .value ,
192
- ... getHeightProp ( collapseRef ) ,
199
+ height: ` ${ collapseRef . value ! . scrollHeight }px ` ,
193
200
})
194
201
195
202
/** Same as for expand, abort transition and force collapse */
@@ -230,6 +237,15 @@ function onTransitionEnd(e: TransitionEvent) {
230
237
if (isExpanded .value ) {
231
238
if (Math .abs (collapseRef .value .scrollHeight - getComputedHeight (collapseRef )) < 1 ) {
232
239
onExpanded ()
240
+ } else if (transitionStartScrollHeight < collapseRef .value .scrollHeight ) {
241
+ /**
242
+ * A child element expanded its height while Collapse
243
+ * is transitioning, update the height and trigger
244
+ * the transition again.
245
+ */
246
+ addStyles ({
247
+ height: ` ${collapseRef .value .scrollHeight }px ` ,
248
+ })
233
249
}
234
250
} else {
235
251
if (Math .abs (baseHeight .value - getComputedHeight (collapseRef )) < 1 ) {
0 commit comments