fix: headlessUI float replace

This commit is contained in:
2026-09-28 21:18:46 +02:00
parent 9eeca7b64c
commit ba7ae10c31
3 changed files with 37 additions and 141 deletions
+33 -41
View File
@@ -1,6 +1,5 @@
import React from "react";
import { Float } from "@headlessui-float/react";
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
import { IoMdMore } from "react-icons/io";
import { twMerge } from "tailwind-merge";
@@ -25,47 +24,40 @@ export const DropdownMenu = ({
}: DropdownMenuProps) => {
return (
<Menu as="div" className={twMerge("relative", containerClassName)}>
<Float
portal
placement="bottom-end"
offset={15}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
{buttonComponent ?? (
<MenuButton>
<IoMdMore />
</MenuButton>
)}
{buttonComponent ?? (
<MenuButton>
<IoMdMore />
</MenuButton>
)}
<MenuItems className="z-20 flex w-auto items-start overflow-hidden rounded-md bg-neutral-200 focus:outline-none dark:bg-neutral-600">
<div className="flex flex-col px-1 py-1">
{items.map(({ title, onClick, className, disabled }, i) => (
<MenuItem key={i}>
<button
type="button"
className={twMerge(
"w-full whitespace-nowrap rounded-md px-2.5 py-2 text-left text-sm text-black dark:text-white",
!disabled && "hover:bg-white dark:hover:bg-neutral-700",
disabled && "text-neutral-500 dark:text-neutral-500",
className,
)}
disabled={disabled ?? false}
onClick={() => {
if (!disabled) onClick();
}}
>
{title}
</button>
</MenuItem>
))}
</div>
</MenuItems>
</Float>
<MenuItems
anchor={{ to: "bottom end", gap: 15 }}
portal
transition
className="z-20 flex w-auto items-start overflow-hidden rounded-md bg-neutral-200 transition ease-out data-[closed]:scale-95 data-[closed]:opacity-0 focus:outline-none dark:bg-neutral-600"
>
<div className="flex flex-col px-1 py-1">
{items.map(({ title, onClick, className, disabled }, i) => (
<MenuItem key={i}>
<button
type="button"
className={twMerge(
"w-full whitespace-nowrap rounded-md px-2.5 py-2 text-left text-sm text-black dark:text-white",
!disabled && "hover:bg-white dark:hover:bg-neutral-700",
disabled && "text-neutral-500 dark:text-neutral-500",
className,
)}
disabled={disabled ?? false}
onClick={() => {
if (!disabled) onClick();
}}
>
{title}
</button>
</MenuItem>
))}
</div>
</MenuItems>
</Menu>
);
};