UIPackage

Dropdown Menu

React overlay
Edit on GitHub

Floating menu launched from a trigger button — for account switchers, row actions, editor menus, and any short list of commands. Supports labels, icons, separators, keyboard shortcuts, checkbox/radio items, and nested submenus. Built on Radix UI; ARIA + keyboard navigation handled.

Also available for Vue ->

Installation

$ npx shadcn@latest add https://react.uipkge.dev/r/react/dropdown-menu.json

Or with the named registry: npx shadcn@latest add @uipkge-react/dropdown-menu

Examples

Dependencies

Used by

Files (2)

  • components/ui/dropdown-menu/dropdown-menu.tsx 9.9 kB
    'use client'
    
    import * as React from 'react'
    import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
    import { Check, ChevronRight, Circle } from 'lucide-react'
    import { cn } from '@/lib/utils'
    
    function DropdownMenu(props: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
      return <DropdownMenuPrimitive.Root data-uipkge="" data-slot="dropdown-menu" {...props} />
    }
    
    function DropdownMenuGroup(props: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
      return <DropdownMenuPrimitive.Group data-uipkge="" data-slot="dropdown-menu-group" {...props} />
    }
    
    function DropdownMenuRadioGroup(props: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
      return <DropdownMenuPrimitive.RadioGroup data-uipkge="" data-slot="dropdown-menu-radio-group" {...props} />
    }
    
    function DropdownMenuSub(props: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
      return <DropdownMenuPrimitive.Sub data-uipkge="" data-slot="dropdown-menu-sub" {...props} />
    }
    
    const DropdownMenuPortal = DropdownMenuPrimitive.Portal
    
    const DropdownMenuTrigger = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.Trigger>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Trigger>
    >(({ ...props }, ref) => (
      <DropdownMenuPrimitive.Trigger ref={ref} data-uipkge="" data-slot="dropdown-menu-trigger" {...props} />
    ))
    DropdownMenuTrigger.displayName = DropdownMenuPrimitive.Trigger.displayName
    
    const DropdownMenuContent = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.Content>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
    >(({ className, sideOffset = 4, ...props }, ref) => (
      <DropdownMenuPrimitive.Portal>
        <DropdownMenuPrimitive.Content
          ref={ref}
          data-uipkge=""
          data-slot="dropdown-menu-content"
          sideOffset={sideOffset}
          className={cn(
            'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md',
            className,
          )}
          {...props}
        />
      </DropdownMenuPrimitive.Portal>
    ))
    DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
    
    const DropdownMenuItem = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.Item>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
        inset?: boolean
        variant?: 'default' | 'destructive'
      }
    >(({ className, inset, variant = 'default', ...props }, ref) => (
      <DropdownMenuPrimitive.Item
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-item"
        data-inset={inset ? '' : undefined}
        data-variant={variant}
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      />
    ))
    DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
    
    const DropdownMenuCheckboxItem = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
    >(({ className, children, checked, ...props }, ref) => (
      <DropdownMenuPrimitive.CheckboxItem
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-checkbox-item"
        checked={checked}
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      >
        <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
          <DropdownMenuPrimitive.ItemIndicator>
            <Check className="size-4" aria-hidden="true" />
          </DropdownMenuPrimitive.ItemIndicator>
        </span>
        {children}
      </DropdownMenuPrimitive.CheckboxItem>
    ))
    DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName
    
    const DropdownMenuRadioItem = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
    >(({ className, children, ...props }, ref) => (
      <DropdownMenuPrimitive.RadioItem
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-radio-item"
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      >
        <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
          <DropdownMenuPrimitive.ItemIndicator>
            <Circle className="size-2 fill-current" />
          </DropdownMenuPrimitive.ItemIndicator>
        </span>
        {children}
      </DropdownMenuPrimitive.RadioItem>
    ))
    DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
    
    const DropdownMenuLabel = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.Label>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & { inset?: boolean }
    >(({ className, inset, ...props }, ref) => (
      <DropdownMenuPrimitive.Label
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-label"
        data-inset={inset ? '' : undefined}
        className={cn('px-2 py-1.5 text-sm font-medium data-[inset]:pl-8', className)}
        {...props}
      />
    ))
    DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
    
    const DropdownMenuSeparator = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
    >(({ className, ...props }, ref) => (
      <DropdownMenuPrimitive.Separator
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-separator"
        className={cn('bg-border -mx-1 my-1 h-px', className)}
        {...props}
      />
    ))
    DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
    
    function DropdownMenuShortcut({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) {
      return (
        <span
          data-uipkge=""
          data-slot="dropdown-menu-shortcut"
          className={cn('text-muted-foreground ml-auto text-xs tracking-widest', className)}
          {...props}
        />
      )
    }
    
    const DropdownMenuSubTrigger = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & { inset?: boolean }
    >(({ className, inset, children, ...props }, ref) => (
      <DropdownMenuPrimitive.SubTrigger
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-sub-trigger"
        data-inset={inset ? '' : undefined}
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring data-[state=open]:bg-accent data-[state=open]:text-accent-foreground data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      >
        {children}
        <ChevronRight className="ml-auto size-4" />
      </DropdownMenuPrimitive.SubTrigger>
    ))
    DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName
    
    const DropdownMenuSubContent = React.forwardRef<
      React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
      React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
    >(({ className, ...props }, ref) => (
      <DropdownMenuPrimitive.SubContent
        ref={ref}
        data-uipkge=""
        data-slot="dropdown-menu-sub-content"
        className={cn(
          'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg',
          className,
        )}
        {...props}
      />
    ))
    DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName
    
    export {
      DropdownMenu,
      DropdownMenuTrigger,
      DropdownMenuContent,
      DropdownMenuGroup,
      DropdownMenuItem,
      DropdownMenuCheckboxItem,
      DropdownMenuRadioGroup,
      DropdownMenuRadioItem,
      DropdownMenuLabel,
      DropdownMenuSeparator,
      DropdownMenuShortcut,
      DropdownMenuSub,
      DropdownMenuSubTrigger,
      DropdownMenuSubContent,
      DropdownMenuPortal,
    }
  • components/ui/dropdown-menu/index.ts 0.4 kB
    export {
      DropdownMenu,
      DropdownMenuTrigger,
      DropdownMenuContent,
      DropdownMenuGroup,
      DropdownMenuItem,
      DropdownMenuCheckboxItem,
      DropdownMenuRadioGroup,
      DropdownMenuRadioItem,
      DropdownMenuLabel,
      DropdownMenuSeparator,
      DropdownMenuShortcut,
      DropdownMenuSub,
      DropdownMenuSubTrigger,
      DropdownMenuSubContent,
      DropdownMenuPortal,
    } from './dropdown-menu'

Raw manifest: https://react.uipkge.dev/r/react/dropdown-menu.json