Skip to content

Commit

Permalink
fix(collapse): ensure to trigger transitionend
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Jul 15, 2022
1 parent 554f93e commit 51b7710
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/varlet-ui/src/collapse-item/CollapseItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</slot>
</div>
</div>
<div :class="n('content')" v-show="show" ref="contentEl" @transitionend="transitionend">
<div :class="n('content')" v-show="show" ref="contentEl" @transitionend="transitionend" @transitionstart="start">
<div :class="n('content-wrap')">
<slot />
</div>
Expand All @@ -30,7 +30,7 @@

<script lang="ts">
import { defineComponent, ref, nextTick, watch, computed } from 'vue'
import { requestAnimationFrame } from '../utils/elements'
import { nextTickFrame, requestAnimationFrame } from '../utils/elements'
import { isArray } from '@varlet/shared'
import { createNamespace } from '../utils/components'
import { useCollapse } from './provide'
Expand All @@ -50,6 +50,7 @@ export default defineComponent({
setup(props) {
const { index, collapse, bindCollapse } = useCollapse()
let isInitToTrigger = true // ensure to trigger transitionend
const contentEl: Ref<HTMLDivElement | null> = ref(null)
const show: Ref<boolean> = ref(false)
const isShow: Ref<boolean> = ref(false)
Expand Down Expand Up @@ -83,10 +84,20 @@ export default defineComponent({
requestAnimationFrame(() => {
;(contentEl.value as HTMLDivElement).style.height = offsetHeight + 'px'
if (!isInitToTrigger) return
nextTickFrame(() => {
if (isInitToTrigger) transitionend()
})
})
})
}
const start = () => {
isInitToTrigger = false
}
const closePanel = () => {
if (!contentEl.value) return
Expand Down Expand Up @@ -121,6 +132,7 @@ export default defineComponent({
return {
n,
start,
classes,
show,
isShow,
Expand Down

0 comments on commit 51b7710

Please sign in to comment.