everweij / react-laag

Hooks to build things like tooltips, dropdown menu's and popovers in React
https://www.react-laag.com
MIT License
907 stars 47 forks source link

[BUG] Animating useLayer doesn't work on first trigger [framer-motion@4.1.13] #69

Closed linden-dg closed 2 years ago

linden-dg commented 3 years ago

Describe the bug The first time a Layer (produced by useLayer) is toggled/triggered open, it doesn't correctly transition from the framer-motion initial state to the animate state (it gets stuck in initial).

It looks like this issue is unique to framer-motion@4.1.13, and could be related to this commit

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/animation-initial-issue-3jbzb?file=/src/index.js
  2. Click on 'Trigger React Laag Layer' button
  3. In the console you can see that isOpen is being toggled true/false
  4. But the first isOpen doesn't properly animate between the initial and animate state
  5. Only when isOpen has been toggled to false, then back to true does the animation work (i.e. 3 clicks needed)
  6. The second button shows that regular framer animations still work just fine on first click

Expected behavior Clicking on the trigger element should open Layer on first go, not require 3 clicks

Browser / OS (please complete the following information):

Additional context Given the regular framer example works, I assume this is a laag/framer-motion interaction. But if it's better to post this on framer-motion, then let me know

everweij commented 2 years ago

I just forked your codesandbox and updated the deps to react-laag@2.0.4 / framer-motion@6.2.9 and it seems like the issue is fixed by now.