CraftUI

Dropdown Menu

A menu of actions from a button, with groups, submenus and destructive actions.

Installation

npx shadcn@latest add @runqora/craft-dropdown-menu

Usage

import { Button } from "@/components/craft/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/craft/dropdown-menu";

<DropdownMenu>
  <DropdownMenuTrigger render={<Button variant="secondary" />}>
    Options
  </DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuItem onClick={copy}>Copy world</DropdownMenuItem>
    <DropdownMenuSeparator />
    <DropdownMenuItem onClick={remove} variant="destructive">
      Delete world
    </DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>;

Examples

Checkbox and radio items

Items that hold a setting stay open when chosen, so you can see the change.

Props

Prop

Type

Prop

Type

Accessibility

  • Enter, Space and Down Arrow open the menu from its trigger, and focus moves to the first item.
  • The arrow keys move between items, skipping disabled ones. Right Arrow opens a submenu and Left Arrow closes it. Typing jumps to a matching item.
  • Escape closes the menu and returns focus to the trigger.
  • Destructive items are red as well as labelled, and turn red when highlighted.

Customization

Pass any element as the trigger with render, such as a CraftUI Button. Set closeOnClick={false} on an item to keep the menu open after choosing it. To go to another page, use DropdownMenuLinkItem with an href.

Dependencies

Source

On this page