Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kpop): duplicate popover elements when transitioning #2239

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/components/KPop/KPop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
</slot>
</div>

<Transition name="kongponents-fade-transition">
<Transition
:key="popoverKey"
name="kongponents-fade-transition"
>
<div
v-show="isVisible"
:key="popoverKey"
ref="popoverElement"
v-bind-once="{ id: popoverId }"
:aria-labelledby="$slots.title || title ? titleId : undefined"
Expand Down Expand Up @@ -84,7 +86,7 @@
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed, watch } from 'vue'
import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue'
import type { PropType } from 'vue'
import { useFloating, autoUpdate, autoPlacement, flip, shift, size } from '@floating-ui/vue'
import type { PopPlacements, PopTrigger } from '@/types'
Expand Down Expand Up @@ -183,13 +185,16 @@ const togglePopover = () => {
}
}

const showPopover = () => {
const showPopover = async () => {
if (!props.disabled) {
if (timer.value) {
clearTimeout(timer.value)
}

popoverKey.value++
if (props.placement !== 'auto') {
popoverKey.value++
await nextTick() // wait for the Transition to update to ensure the animation works as expected
}
isVisible.value = true
}
}
Expand Down