# Dropdown menu

shadcn dropdown menu with Win95 inverted highlight, etched separators and pixel indicators.

Source: https://www.ui95.dev/ui/dropdown-menu

## Examples

```tsx
import { useState } from "react"

import { Button } from "@/components/ui/button"
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

import type { ShowcaseDemo } from "../types"

function renderTrigger(label: string) {
  return (
    <DropdownMenuTrigger asChild>
      <Button size="sm" className="self-center">
        {label}
      </Button>
    </DropdownMenuTrigger>
  )
}

function renderItemsMenu() {
  return (
    <DropdownMenu>
      {renderTrigger("File")}
      <DropdownMenuContent>
        <DropdownMenuLabel>Document</DropdownMenuLabel>
        <DropdownMenuGroup>
          <DropdownMenuItem>
            New
            <DropdownMenuShortcut>Ctrl+N</DropdownMenuShortcut>
          </DropdownMenuItem>
          <DropdownMenuItem>
            Open...
            <DropdownMenuShortcut>Ctrl+O</DropdownMenuShortcut>
          </DropdownMenuItem>
          <DropdownMenuItem disabled>
            Save
            <DropdownMenuShortcut>Ctrl+S</DropdownMenuShortcut>
          </DropdownMenuItem>
        </DropdownMenuGroup>
        <DropdownMenuSeparator />
        <DropdownMenuItem inset>Print preview</DropdownMenuItem>
        <DropdownMenuItem variant="destructive">Delete</DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

function SelectionMenu() {
  const [isStatusBarVisible, setIsStatusBarVisible] = useState(true)
  const [isGridVisible, setIsGridVisible] = useState(false)
  const [zoom, setZoom] = useState("100")

  return (
    <DropdownMenu>
      {renderTrigger("View")}
      <DropdownMenuContent>
        <DropdownMenuCheckboxItem checked={isStatusBarVisible} onCheckedChange={setIsStatusBarVisible}>
          Status bar
        </DropdownMenuCheckboxItem>
        <DropdownMenuCheckboxItem checked={isGridVisible} onCheckedChange={setIsGridVisible}>
          Grid
        </DropdownMenuCheckboxItem>
        <DropdownMenuSeparator />
        <DropdownMenuLabel inset>Zoom</DropdownMenuLabel>
        <DropdownMenuRadioGroup value={zoom} onValueChange={setZoom}>
          <DropdownMenuRadioItem value="100">100%</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="200">200%</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="400">400%</DropdownMenuRadioItem>
        </DropdownMenuRadioGroup>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

function renderSubmenu() {
  return (
    <DropdownMenu>
      {renderTrigger("Tools")}
      <DropdownMenuContent>
        <DropdownMenuItem>Defragment</DropdownMenuItem>
        <DropdownMenuSub>
          <DropdownMenuSubTrigger>Accessories</DropdownMenuSubTrigger>
          <DropdownMenuSubContent>
            <DropdownMenuItem>Calculator</DropdownMenuItem>
            <DropdownMenuItem>Notepad</DropdownMenuItem>
            <DropdownMenuItem>Paint</DropdownMenuItem>
          </DropdownMenuSubContent>
        </DropdownMenuSub>
        <DropdownMenuSeparator />
        <DropdownMenuItem>Shut down...</DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

export const demo: ShowcaseDemo = {
  span: "single",
  variants: [
    { label: "items, shortcuts, disabled, inset, destructive", render: renderItemsMenu },
    { label: "checkbox and radio", render: () => <SelectionMenu /> },
    { label: "submenu", render: renderSubmenu },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/dropdown-menu.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/dropdown-menu.tsx`

```tsx
"use client"

import { cn } from "cn"
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
import * as React from "react"

import { ArrowGlyph, CheckGlyph, DotGlyph } from "@/components/ui/pixel-glyphs"

function DropdownMenu({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
  return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
}

function DropdownMenuPortal({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
  return (
    <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
  )
}

function DropdownMenuTrigger({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
  return (
    <DropdownMenuPrimitive.Trigger
      data-slot="dropdown-menu-trigger"
      {...props}
    />
  )
}

function DropdownMenuContent({
  className,
  align = "start",
  sideOffset = 4,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
  return (
    <DropdownMenuPrimitive.Portal>
      <DropdownMenuPrimitive.Content
        data-slot="dropdown-menu-content"
        sideOffset={sideOffset}
        align={align}
        className={cn(
          "z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-40 overflow-x-hidden overflow-y-auto pixel-border border-border bg-popover p-(--pixel) text-popover-foreground offset-shadow-2",
          className
        )}
        {...props}
      />
    </DropdownMenuPrimitive.Portal>
  )
}

function DropdownMenuGroup({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
  return (
    <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
  )
}

function DropdownMenuItem({
  className,
  inset,
  variant = "default",
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
  inset?: boolean
  variant?: "default" | "destructive"
}) {
  return (
    <DropdownMenuPrimitive.Item
      data-slot="dropdown-menu-item"
      data-inset={inset}
      data-variant={variant}
      className={cn(
        "group/dropdown-menu-item relative flex h-8 items-center gap-2 px-2 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive data-[variant=destructive]:focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
        className
      )}
      {...props}
    />
  )
}

function DropdownMenuCheckboxItem({
  className,
  children,
  checked,
  inset,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
  inset?: boolean
}) {
  return (
    <DropdownMenuPrimitive.CheckboxItem
      data-slot="dropdown-menu-checkbox-item"
      data-inset={inset}
      className={cn(
        "relative flex h-8 items-center gap-2 pr-2 pl-7 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
        className
      )}
      checked={checked}
      {...props}
    >
      <span
        className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center"
        data-slot="dropdown-menu-checkbox-item-indicator"
      >
        <DropdownMenuPrimitive.ItemIndicator>
          <CheckGlyph />
        </DropdownMenuPrimitive.ItemIndicator>
      </span>
      {children}
    </DropdownMenuPrimitive.CheckboxItem>
  )
}

function DropdownMenuRadioGroup({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
  return (
    <DropdownMenuPrimitive.RadioGroup
      data-slot="dropdown-menu-radio-group"
      {...props}
    />
  )
}

function DropdownMenuRadioItem({
  className,
  children,
  inset,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
  inset?: boolean
}) {
  return (
    <DropdownMenuPrimitive.RadioItem
      data-slot="dropdown-menu-radio-item"
      data-inset={inset}
      className={cn(
        "relative flex h-8 items-center gap-2 pr-2 pl-7 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
        className
      )}
      {...props}
    >
      <span
        className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center"
        data-slot="dropdown-menu-radio-item-indicator"
      >
        <DropdownMenuPrimitive.ItemIndicator>
          <DotGlyph />
        </DropdownMenuPrimitive.ItemIndicator>
      </span>
      {children}
    </DropdownMenuPrimitive.RadioItem>
  )
}

function DropdownMenuLabel({
  className,
  inset,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
  inset?: boolean
}) {
  return (
    <DropdownMenuPrimitive.Label
      data-slot="dropdown-menu-label"
      data-inset={inset}
      className={cn(
        "px-2 pt-2 pb-1 font-pixel text-sm leading-none text-muted-foreground uppercase data-inset:pl-7",
        className
      )}
      {...props}
    />
  )
}

function DropdownMenuSeparator({
  className,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
  return (
    <DropdownMenuPrimitive.Separator
      data-slot="dropdown-menu-separator"
      className={cn(
        "mx-1 my-1 border-t-(length:--pixel) border-b-(length:--pixel) border-t-bevel-lo border-b-bevel-hi",
        className
      )}
      {...props}
    />
  )
}

function DropdownMenuShortcut({
  className,
  ...props
}: React.ComponentProps<"span">) {
  return (
    <span
      data-slot="dropdown-menu-shortcut"
      className={cn(
        "ml-auto pl-4 text-lg leading-none text-muted-foreground group-focus/dropdown-menu-item:text-popover",
        className
      )}
      {...props}
    />
  )
}

function DropdownMenuSub({
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
  return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
}

function DropdownMenuSubTrigger({
  className,
  inset,
  children,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
  inset?: boolean
}) {
  return (
    <DropdownMenuPrimitive.SubTrigger
      data-slot="dropdown-menu-sub-trigger"
      data-inset={inset}
      className={cn(
        "flex h-8 items-center gap-2 px-2 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-inset:pl-7 data-open:bg-foreground data-open:text-popover [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
        className
      )}
      {...props}
    >
      {children}
      <ArrowGlyph direction="right" className="ml-auto" />
    </DropdownMenuPrimitive.SubTrigger>
  )
}

function DropdownMenuSubContent({
  className,
  ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
  return (
    <DropdownMenuPrimitive.SubContent
      data-slot="dropdown-menu-sub-content"
      className={cn(
        "z-50 min-w-32 overflow-hidden pixel-border border-border bg-popover p-(--pixel) text-popover-foreground offset-shadow-2",
        className
      )}
      {...props}
    />
  )
}

export {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuPortal,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
}
```

## API reference

### DropdownMenu

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuCheckboxItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### DropdownMenuContent

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuGroup

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |
| `variant` | `"default" \| "destructive"` | `"default"` |

### DropdownMenuLabel

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### DropdownMenuPortal

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuRadioGroup

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuRadioItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### DropdownMenuSeparator

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuShortcut

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuSub

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuSubContent

No props of its own. It forwards the props of the element or primitive it wraps.

### DropdownMenuSubTrigger

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### DropdownMenuTrigger

No props of its own. It forwards the props of the element or primitive it wraps.

## Used by

- [taskbar](https://www.ui95.dev/ui/taskbar)

## Sounds

- `menu.select`
