Skip to content

transition-group item with flex parent moves to top-left #9713

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

Closed
franciscolourenco opened this issue Mar 15, 2019 · 5 comments
Closed

transition-group item with flex parent moves to top-left #9713

franciscolourenco opened this issue Mar 15, 2019 · 5 comments

Comments

@franciscolourenco
Copy link
Contributor

Version

2.6.8

Reproduction link

https://codepen.io/andymerskin/pen/eRNvLR

Steps to reproduce

  1. Click in any rectangle except the first one

What is expected?

The rectangle should fade out, but not move

What is actually happening?

The rectagle moves to the left-top corner while fading away


This seems to be caused by the flex parent combined with absolute positioning of the rectangle leaving

Related

@posva
Copy link
Member

posva commented Mar 15, 2019

it goes to the top because you are using position absolute

@posva posva closed this as completed Mar 15, 2019
@franciscolourenco
Copy link
Contributor Author

franciscolourenco commented Mar 15, 2019 via email

@posva
Copy link
Member

posva commented Mar 15, 2019

I'm saying that this is working correctly: absolute makes it go to the top left in the flex container even without top or left (not the case with a regular container) and because it's in a transition group, Vue adds the transform attribute (to move things) making it move to the top left

@sofuxro
Copy link

sofuxro commented Jan 8, 2020

Same issue for flex and grid

Found this solutions:

<transition-group
    @before-leave="beforeLeave">
    ...
</transition>
methods: {
    beforeLeave(el) {
        const {marginLeft, marginTop, width, height} = window.getComputedStyle(el)

        el.style.left = `${el.offsetLeft - parseFloat(marginLeft, 10)}px`
        el.style.top = `${el.offsetTop - parseFloat(marginTop, 10)}px`
        el.style.width = width
        el.style.height = height
    }
}

thanks to docmars in forum.vuejs.org

@adamreisnz
Copy link

The reason position: absolute is added is likely to accomplish this effect: https://vuejs.org/guide/built-ins/transition-group#move-transitions

In the example, this works fine. But when using a flex parent container, the items move to the top of the container the moment they are animated away, which is an undesired side effect.

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

4 participants