Skip to content

Commit b852423

Browse files
committed
improved menu component type safety
1 parent ae6b7c8 commit b852423

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/ui/Menu/Menu.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import { cn } from "@/lib/utils";
44
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
5-
import React, { HTMLAttributes } from "react";
5+
import React, { ComponentPropsWithoutRef, HTMLAttributes } from "react";
66

77
const Menu = DropdownMenu.Root;
88
const Trigger = DropdownMenu.Trigger;
99

10-
interface IMenuContent extends HTMLAttributes<HTMLDivElement> {
11-
children: React.ReactNode;
12-
}
10+
interface IMenuContent
11+
extends ComponentPropsWithoutRef<typeof DropdownMenu.Content> {}
1312

1413
const Content = ({ className, ...props }: IMenuContent) => (
1514
<DropdownMenu.Portal>
@@ -25,12 +24,20 @@ const Content = ({ className, ...props }: IMenuContent) => (
2524
</DropdownMenu.Portal>
2625
);
2726

28-
const MenuItem = (props: any) => (
27+
const MenuItem = React.forwardRef<
28+
HTMLDivElement,
29+
ComponentPropsWithoutRef<typeof DropdownMenu.Item>
30+
>(({ className, ...props }, ref) => (
2931
<DropdownMenu.Item
30-
className="p-2 hover:bg-primary-400 outline-none cursor-pointer "
32+
ref={ref}
33+
className={cn(
34+
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-primary-400 hover:text-white focus:bg-primary-400 focus:text-white data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
35+
className
36+
)}
3137
{...props}
3238
/>
33-
);
39+
));
40+
MenuItem.displayName = "MenuItem";
3441

3542
const MenuComponent = Object.assign(Menu, {
3643
Trigger,

0 commit comments

Comments
 (0)