-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Example with popper + portal + transition #154
Comments
Ok, I figured it out. Here is a working example adapted from Transition+Menu example here: https://codesandbox.io/s/headlessuireact-transitionmenupopper-example-forked-zl7zg It is using the dev version of headlessui, because I needed callbacks for beforeEnter and afterLeave. I also used the official react-popper hook, as opposed to what other examples in headlessui use - you'd probably want to use an offical hook anyway. Main changes are:
The example might be simplified, but it's a good working base for implementation. |
@vincaslt thanks for the example! This is really cool. +1 to adding more samples like this to the main docs 👍🏻 |
Great example, saved me hours of coding! thank you! |
@vincaslt Thanks for the example. Your example inspired me to create a package Headless UI Float, that can be easy to position floating Headless UI elements using Floating UI, support Transition & Portal. The example below is a fork from your example, but replace Popper.js with my created package: |
Hi All, I faced similar issue when I use So based on this I have fixed issue with popper adding dynamic styles to menu items container is fixed Thanks @vincaslt |
Small update regarding floating-ui that this excellent technique of @vincaslt still work: The key elements are the same:
|
Could we get an example of usage with popper and transition in portal?
This example is helpful: https://github.com/tailwindlabs/headlessui/blob/develop/packages/%40headlessui-react/pages/menu/menu-with-transition-and-popper.tsx
However, it doesn't work when we put Portal into play. Just wrapping with Portal will either remove transitions or the dropdown will disappear after the transition depending on what you wrap inside of your Portal.
I kinda made it work (using their own hook) with code like this:
It animates enter, but it fails to animate leave though. Also, this is only a custom dropdown element, it becomes even more complicated and fragile with Listbox or Menu. Similar approach worked for Menu, but for Listbox, even enter animations did not work until I added
transform opacity-0 scale-95
to className for Listbox.Options in addition to Transition, which is super unintuitive.Can we get a proper example? Maybe some errors will get fixed in the process too
The text was updated successfully, but these errors were encountered: