2026-02-06 01:27:29 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
import type { DropdownMenuItemProps } from './types';
|
|
|
|
|
|
|
|
|
|
export const DropdownMenuItem = React.forwardRef<
|
|
|
|
|
HTMLButtonElement,
|
|
|
|
|
DropdownMenuItemProps
|
|
|
|
|
>(({ className, inset, onKeyDown, onClick, ...props }, ref) => {
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
|
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (onClick && !props.disabled) {
|
|
|
|
|
(onClick as (e: React.KeyboardEvent<HTMLButtonElement>) => void)(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onKeyDown?.(e);
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
ref={ref}
|
|
|
|
|
type="button"
|
|
|
|
|
role="menuitem"
|
|
|
|
|
className={cn(
|
|
|
|
|
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none',
|
|
|
|
|
'transition-colors focus:bg-white/5 focus:text-white disabled:pointer-events-none disabled:opacity-50',
|
2026-02-07 13:23:04 +00:00
|
|
|
'text-foreground hover:bg-muted/50 w-full text-left',
|
2026-02-06 01:27:29 +00:00
|
|
|
inset && 'pl-8',
|
|
|
|
|
className,
|
|
|
|
|
)}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
DropdownMenuItem.displayName = 'DropdownMenuItem';
|