Skip to content

Example with popper + portal + transition #154

@vincaslt

Description

@vincaslt

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:

<Portal>
  <Transition
    show={isOpen}
    enter="transition ease-out duration-100"
    enterFrom="transform opacity-0 scale-95"
    enterTo="transform opacity-100 scale-100"
    leave="transition ease-in duration-750"
    leaveFrom="transform opacity-100 scale-100"
    leaveTo="transform opacity-0 scale-95"
  >
    {(ref) => (
      <div
        ref={setPopperElement}
        {...popperProps}
      >
        <div
          ref={ref}
        >
          {children}
        </div>
      </div>
    )}
  </Transition>
</Portal>

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

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