DEV Community

wolfiton
wolfiton

Posted on

Does Vue slotted content not inherite the transition of the parent?

Hi everyone,

So working on one of my projects, I created a menu animation with some default content and a named slot.

The slot, when used in another component, works but doesn't keep the animation of the menu parent, it becomes static.

This is how I expect this animation to work, this example doesn't use the slotted content menu-h animation link
The link is a live version.

My question is:

Does the VUE slotted content, not keep the parent's transition?

Thanks in advance for any resource or explanation regarding this matter.

I followed this guide vue slot guide

Top comments (5)

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

It sounds like you may be experiencing the issue outlined here:

slot can't use in vue transtion component #4414

yonycat avatar
yonycat commented on Dec 08, 2016

Soucce code of defined transition-demo component

<template>
  <div class="doc-ctn computed">
    <h4 class="ctn-title">transition</h4>
    <div class="ctn-demo">

      <transition name="demo">
        <!-- slot fangzai   -->
        <slot ></slot>
      </transition>
    </div>
  </div>
</template>

Then i use transition demo component in parent component:

<transition-demo>
        I am disappearing
</transition-demo>

content ' I am disappearing' dose not rendered.

If not could you provide a bit more detail about your code - preferably a sample or similar code in a online editor like Codepen.

Collapse
 
wolfiton profile image
wolfiton • Edited

Thanks for the link and ideas @tylerv, I really appreciated your input on my problem.

I am going to create a sandbox or codepen for this problem.

I created a codesandbox codesandbox link

So the following files are important here:

  • HorizontalMenu.vue located in src/components
  • MainLayout.vue located in src/layouts
  • App.vue located in src
Collapse
 
terabytetiger profile image
Tyler V. (he/him)

For making this easier to explain, I'm going to be using showing instead of show for the data in layouts/MainLayout.vue

I believe the issue is that when you use a <slot> the parent file that is passing in your slot values is the context that the slot contents will see. So when you click your menu button in your component, you're toggling show between true and false, but your slot is looking at the showing value.

There's also an issue where having a transition wrapping a transition will throw errors.

I forked your repo and have the transitions working here: codesandbox.io/s/serene-cori-kksi2

Thread Thread
 
wolfiton profile image
wolfiton • Edited

Thanks @tylerv for the help I will credit you in the github repo of the menu component, would that be alright with you?

Also, can I improve my component to make it more flexible in any way?(any suggestions regarding this idea)

Thanks again

Thread Thread
 
terabytetiger profile image
Tyler V. (he/him)

If you want to, it's always appreciated - but no need, I'm here to help πŸ˜„

As for your components being flexible, I think that depends on how you're planning to use them in the future - if you want to DM me and talk some more about this, feel free! My DMs should be open πŸ™‚