Skip to content

List transitions behave differently with display: grid vs flex #225

@robertbel

Description

@robertbel

This may just be a CSS limitation, but I’d appreciate any direction or advice on how to approach this and how to know these kind of things are not related to motion-v.

Vite.App.-.Google.Chrome.2026-01-12.13-57-13.mp4

1. Describe what is happening

I want to display modals in a somewhat unique way: the last opened modal should be on its own, while the rest are stacked on the left. I thought I was being clever by using the stacking “trick” with display: grid, but this causes things to look bad when closing the last/right modal. I feel like this should just work, because with display: flex everything behaves as expected when closing modals.

In my example, I have:

  • A modal-container that displays the modals from the openModal array
  • A button to add new modals
  • Each modal has a close button

With display: flex on the modal-container:

  • The animation for adding modals is correct ✅
  • The animation for removing modals is correct ✅
  • The overall layout is wrong (I want stacked modals) ❌

With display: grid on the modal-container:

  • The animation for adding modals is correct ✅
  • The animation for removing modals is wrong ❌
  • The overall layout is correct (modal stacking) ✅

2. CodeSandbox reproduction

https://codesandbox.io/p/sandbox/motion-modals-f4qrck


3. Steps to reproduce

  1. Toggle “Toggle display property” to set it to display: grid;
  2. Add a few modals (looks good!)
  3. Close the modal on the right (this looks bad and is what I’m trying to fix)

4. Expected behavior

When using display: grid, the next modal in the stack (on the left) should slide over smoothly, just like it does when using display: flex.


6. Environment details

Any browsers. Used dependencies are:

"@vueuse/core": "^14.1.0", "motion-v": "^1.8.1", "vue": "^3.5.22",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions