Replies: 1 comment 1 reply
-
I found a solution. Using the import { useState, useRef } from "react";
import { Popover } from "@headlessui/react";
import {
useFloating,
useTransitionStatus,
flip,
autoUpdate,
} from "@floating-ui/react";
export default function App() {
const [show, setShow] = useState(false);
const { context, x, y, strategy, placement, refs } = useFloating({
open: show,
placement: "bottom-start",
middleware: [flip()],
whileElementsMounted: autoUpdate,
});
const { isMounted, status } = useTransitionStatus(context);
return (
<div className="relative h-[400px] p-4 border border-black overflow-y-auto">
<Popover className="py-[300px]">
<Popover.Button
ref={refs.setReference}
onClick={() => setShow((show) => !show)}
>
Button
</Popover.Button>
{isMounted && (
<Popover.Panel
static
className="
w-[200px] h-[100px] border border-black
data-[status=open]:transition data-[status=open]:duration-200
data-[status=initial]:opacity-0
data-[status=initial]:data-[placement^=top]:translate-y-4
data-[status=initial]:data-[placement^=bottom]:-translate-y-4
data-[status=close]:transition data-[status=close]:duration-200
data-[status=close]:opacity-0
data-[status=close]:data-[placement^=top]:translate-y-4
data-[status=close]:data-[placement^=bottom]:-translate-y-4
"
ref={refs.setFloating}
style={{
position: strategy,
top: y ?? 0,
left: x ?? 0,
}}
data-placement={placement}
data-status={status}
>
content...
</Popover.Panel>
)}
</Popover>
</div>
);
}
This is the solution I found so far, but I don't know how to achieve the same goal using only the Transition component of Headless UI. Is there any chance that Headless UI can solve this problem? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think the issue #2550 is still not resolved. I have made the changes based on your suggestions, but the bug is still present.
Below is the updated repo URL:
https://codesandbox.io/p/sandbox/headlessui-transition-with-floatingui-update-placement-bug-updated-y2hhrj?file=%2Fsrc%2FApp.jsx
And follow the reproduction steps will see the bug is still present.
Beta Was this translation helpful? Give feedback.
All reactions