Skip to Content
Neshel-UI
Components

DropdownMenu

A menu of commands with items, checkbox and radio items, labels, groups, shortcuts and submenus.

Client component ("use client")

Purpose

DropdownMenu shows a list of commands from a trigger: account menus, row actions, toolbar overflow. It uses menu semantics (menu, menuitem, menuitemcheckbox, menuitemradio).

Import

import.tsx
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@neshel-ui/components";

Usage

Preview: dropdown-menu-commands
Preview theme
last command: none
dropdown-menu-commands.tsx
"use client";
import {
  Button,
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
} from "@neshel-ui/components";
import { Inline } from "@neshel-ui/layout";
import { Text } from "@neshel-ui/typography";
import { useState } from "react";

export default function DropdownMenuCommands() {
  const [density, setDensity] = useState("comfortable");
  const [notifications, setNotifications] = useState(true);
  const [last, setLast] = useState("none");
  return (
    <Inline space="3" align="center">
      <DropdownMenu>
        <DropdownMenuTrigger asChild>
          <Button variant="outline">Account</Button>
        </DropdownMenuTrigger>
        <DropdownMenuContent align="start">
          <DropdownMenuLabel>My account</DropdownMenuLabel>
          <DropdownMenuGroup>
            <DropdownMenuItem onSelect={() => setLast("profile")}>
              Profile <DropdownMenuShortcut>⌘P</DropdownMenuShortcut>
            </DropdownMenuItem>
            <DropdownMenuItem onSelect={() => setLast("settings")}>Settings</DropdownMenuItem>
          </DropdownMenuGroup>
          <DropdownMenuSeparator />
          <DropdownMenuCheckboxItem checked={notifications} onCheckedChange={setNotifications}>
            Notifications
          </DropdownMenuCheckboxItem>
          <DropdownMenuRadioGroup value={density} onValueChange={setDensity}>
            <DropdownMenuRadioItem value="comfortable">Comfortable</DropdownMenuRadioItem>
            <DropdownMenuRadioItem value="compact">Compact</DropdownMenuRadioItem>
          </DropdownMenuRadioGroup>
          <DropdownMenuSub>
            <DropdownMenuSubTrigger>Invite</DropdownMenuSubTrigger>
            <DropdownMenuSubContent>
              <DropdownMenuItem onSelect={() => setLast("email")}>Email</DropdownMenuItem>
              <DropdownMenuItem onSelect={() => setLast("link")}>Copy link</DropdownMenuItem>
            </DropdownMenuSubContent>
          </DropdownMenuSub>
          <DropdownMenuSeparator />
          <DropdownMenuItem variant="destructive" onSelect={() => setLast("sign-out")}>
            Sign out
          </DropdownMenuItem>
        </DropdownMenuContent>
      </DropdownMenu>
      <Text tone="muted" size="sm">
        last command: {last}
      </Text>
    </Inline>
  );
}

API

DropdownMenuProps

Also accepts the props of: @radix-ui/react-dropdown-menu.

DropdownMenuTriggerProps

DropdownMenuTriggerProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DropdownMenuContentProps

DropdownMenuContentProps
PropTypeDefaultDescription
containerHTMLElement | nulldocument.bodyPortal target (default document.body, wrapped with the trigger's theme).
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-popper, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuItemProps

DropdownMenuItemProps
PropTypeDefaultDescription
insetboolean—Indent to align with items that have an indicator or icon.
refRef<HTMLDivElement>——
variant"default" | "destructive""default"Use "destructive" for dangerous commands (default "default").

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuCheckboxItemProps

DropdownMenuCheckboxItemProps
PropTypeDefaultDescription
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuRadioGroupProps

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuRadioItemProps

DropdownMenuRadioItemProps
PropTypeDefaultDescription
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuLabelProps

DropdownMenuLabelProps
PropTypeDefaultDescription
insetboolean—Indent to align with items that have an indicator or icon.
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DropdownMenuGroupProps

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DropdownMenuSeparatorProps

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DropdownMenuShortcutProps

DropdownMenuShortcutProps
PropTypeDefaultDescription
refRef<HTMLSpanElement>——

Also accepts the props of: React DOM attributes.

DropdownMenuSubProps

Also accepts the props of: @radix-ui/react-dropdown-menu.

DropdownMenuSubTriggerProps

DropdownMenuSubTriggerProps
PropTypeDefaultDescription
insetboolean—Indent to align with items that have an indicator or icon.
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-primitive, React DOM attributes.

DropdownMenuSubContentProps

DropdownMenuSubContentProps
PropTypeDefaultDescription
containerHTMLElement | nulldocument.bodyPortal target (default document.body, wrapped with the trigger's theme).
refRef<HTMLDivElement>——

Also accepts the props of: @radix-ui/react-menu, @radix-ui/react-popper, @radix-ui/react-primitive, React DOM attributes.

  • Run commands in onSelect (keyboard and pointer). The menu closes after a selection; call event.preventDefault() in onSelect to keep it open.
  • DropdownMenuItem variant="destructive" styles dangerous commands.
  • DropdownMenuShortcut only displays a shortcut; register the key binding yourself.

Controlled and uncontrolled

Menu: open / defaultOpen / onOpenChange. Checkbox items: checked / onCheckedChange. Radio groups: value / onValueChange.

Accessibility

Focus moves into the menu on open and returns to the trigger on close. Items are announced with their role and checked state. Labels (DropdownMenuLabel) and separators structure long menus.

Keyboard

KeyAction
Enter / Space / ↓Open from the trigger
↓ / ↑, Home / EndMove between items
Type lettersJump to a matching item
→ / ←Open / close a submenu
Enter / SpaceActivate the item
EscapeClose the menu (innermost first)

Common mistakes

  • Navigation links in a DropdownMenu: users of screen readers expect commands. Use a NavigationMenu or plain links.
  • Using onClick instead of onSelect — keyboard activation would be missed.
Edit on GitHub

On this page