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

[BUG]display: 'none' can not be set #2563

Open
futugyou opened this issue Mar 16, 2024 · 8 comments
Open

[BUG]display: 'none' can not be set #2563

futugyou opened this issue Mar 16, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@futugyou
Copy link

when use 'useAnimate', the 'display:none' can not be set ,but other e.g.'display:inline' is ok.

package version "framer-motion": "^11.0.14"

import React, { useState, useEffect } from "react"
import { useAnimate } from "framer-motion"
...
const FlowPanel = () => {
  const [showMenu, setShowMenu] = useState(false)
  const [scope, animate] = useAnimate()
  
  useEffect(() => {
          const menus = document.getElementsByClassName("flow-panel-menu")
          if (menus.length <= 0) {
              return
          }
  
          const enterAnimation = () => {
              const current = menus[0]
              if (showMenu) {
                  animate(current, { opacity: 1, display: 'inline' }, { duration: 0.7 })
              } else {
                  animate(current, { opacity: 0, display: 'none' }, { duration: 0.7 })
              }
          }
  
          enterAnimation()
      }, [showMenu])

 return (
<div className="flow-panel-menu" ref={scope} >
                    ...
</div>
    )
}

when i set showMenu state to 'false', the 'opacity: 0' will be set correctly, but 'display' will still 'inline'.
if i write the else code like animate(current, { opacity: 0, display: 'contents' }, { duration: 0.7 }), the 'display' will set 'contents'.
i means only display: 'none' cannot be set correctly.

@futugyou futugyou added the bug Something isn't working label Mar 16, 2024
@AbdullahZulfikar
Copy link

So your problem is that it is not setting to none; instead, it is setting to content?

@futugyou
Copy link
Author

futugyou commented Mar 17, 2024

So your problem is that it is not setting to none; instead, it is setting to content?

That was not what I meant,

 if (showMenu) {
                  animate(current, { opacity: 1, display: 'inline' }, { duration: 0.7 })
              } else {
                  animate(current, { opacity: 0, display: 'none' }, { duration: 0.7 })
              }

In this case, if the else branch is reached, the 'opacity: 0' will be set , but 'display' will still 'inline'

 if (showMenu) {
                  animate(current, { opacity: 1, display: 'inline' }, { duration: 0.7 })
              } else {
                  animate(current, { opacity: 0, display: 'content' }, { duration: 0.7 })
              }

In this case, if the else branch is reached, the 'opacity: 0' will be set , and 'display' is setting to 'content'.

So my conclusion is only display: 'none' cannot be set correctly.

@AndreaEsposit
Copy link

Same thing happening to us

@tien
Copy link

tien commented Mar 28, 2024

In my case, display property stopped working properly entirely unless you have them as part of transitionEnd

tien added a commit to TalismanSociety/talisman-web that referenced this issue Mar 28, 2024
tien added a commit to TalismanSociety/talisman-web that referenced this issue Mar 28, 2024
@tien
Copy link

tien commented Apr 5, 2024

🏓 @mattgperry

@AndreaEsposit
Copy link

Any update on this?

@debs-07
Copy link

debs-07 commented Apr 25, 2024

Facing the same issue. Setting display : flex is working but display : none is not working while all other style properties are animating as expected. Any updates on this?

With transitionEnd display : none is working

@modulareverything
Copy link

I just ran into this myself upgrading from v10.16.16 to v11.1.7, suddenly my animations were looking a little weird.

Changing to transitionEnd seemed to work. I imagine this is intentional as it's mentioned here:

https://www.framer.com/motion/component/##value-types

For me, this:

<motion.span
  variants={{
    open: {
      opacity: 0,
      display: 'none',
    },
    closed: {
      opacity: 1,
      display: 'block',
    },
  }}
  animate={menuOpen ? "open" : "closed"}
  className="block"
>
  Menu
</motion.span>

became this:

<motion.span
  variants={{
    open: {
      opacity: 0,
      transitionEnd: {
        display: "none",
      },
    },
    closed: {
      opacity: 1,
      transitionEnd: {
        display: "block",
      },
    },
  }}
  animate={menuOpen ? "open" : "closed"}
  className="block"
>
  Menu
</motion.span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants