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

How to interact with multiple instances of the same transition? #26

Closed
Fanna1119 opened this issue Jul 11, 2021 · 2 comments
Closed

How to interact with multiple instances of the same transition? #26

Fanna1119 opened this issue Jul 11, 2021 · 2 comments

Comments

@Fanna1119
Copy link

Fanna1119 commented Jul 11, 2021

I have a component as followed.

//motionfx.vue

<template>
    <transition @leave="(el, done) => motions.notification.leave(done)">
        <div
            v-if="copied"
            v-motion-pop="'notification'"
            class="bg-yellow-300 fixed py-4 px-8 rounded-full bottom-16 right-4 z-10"
        >
            <p class="text-yellow-900">Message Copied!</p>

            <button
                class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
                @click="copied = !copied"
            >closenotification</button>
        </div>
    </transition>

    <button
        class="py-4 px-8 rounded-full bottom-16 right-4 bg-red-600"
        @click="copied = !copied"
    >Open</button>
</template>

<script>
import { useMotions } from '@vueuse/motion'
import { ref } from '@vue/reactivity'
export default {

    setup() {
        const copied = ref(false)
        const motions = useMotions()

        return {
            copied, motions
        }
    }

}
</script>

in my parent where the component is initiated multiple times.:

    <motionfx></motionfx>
    <motionfx></motionfx>
    <motionfx></motionfx>
    <motionfx></motionfx>
    <motionfx></motionfx>

it functions as expected, up until i open multiple components and then clicking 'close'/@Leave transition.

Cannot read property 'leave' of undefined

I am assuming it is something to do with:
https://motion.vueuse.org/api/use-motions.html

If you declare a name using v-motion attribute value, the motion instances will be added to the global useMotions state and be accessible from any component.

Be careful about duplicating the same name, note that the name can be including a variable.

Of course I don't understand how to get around this. :)

@Tahul
Copy link
Member

Tahul commented Aug 19, 2021

Hello @Fanna1119 😄

Maybe the documentation is unclear about this point, but you should be giving unique names to each of these components.

Maybe adding a prop to it specifying a key (or generating a random id for each from inside the component) should be enough for that. 😄

Let me know if you struggle with this, would be happy to help!

@Tahul
Copy link
Member

Tahul commented Aug 19, 2021

I'm closing this, feel free to re-open if any more questions.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants