Overlays

Dropdown menu

A button that opens a list of commands.

Client component7 exportsSource

Import

import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from '@the_viveksingh/vivek-ui'

A menu of actions

role="menu" with the full keyboard map: arrows move, typeahead jumps, Escape closes and returns focus to the trigger. shortcut is display only - bind the key yourself.

<DropdownMenu>
  <DropdownMenuTrigger>Actions</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuLabel>Invoice INV-1042</DropdownMenuLabel>
    <DropdownMenuItem shortcut="E" onSelect={edit}>Edit</DropdownMenuItem>
    <DropdownMenuItem shortcut="D" onSelect={duplicate}>Duplicate</DropdownMenuItem>
    <DropdownMenuSeparator />
    <DropdownMenuItem disabled>Send reminder</DropdownMenuItem>
    <DropdownMenuItem onSelect={remove}>Delete</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Checkbox items

closeOnSelect={false} keeps the menu open so several columns can be toggled in one pass, which is what a column picker needs.

<DropdownMenu>
  <DropdownMenuTrigger>View options</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuLabel>Columns</DropdownMenuLabel>
    <DropdownMenuCheckboxItem defaultChecked closeOnSelect={false}>Invoice</DropdownMenuCheckboxItem>
    <DropdownMenuCheckboxItem defaultChecked closeOnSelect={false}>Client</DropdownMenuCheckboxItem>
    <DropdownMenuCheckboxItem closeOnSelect={false}>Tax</DropdownMenuCheckboxItem>
    <DropdownMenuSeparator />
    <DropdownMenuItem shortcut="R">Reset to defaults</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Props

Generated from the package's own type declarations, so this table cannot drift from the code.

Props for DropdownMenu
PropTypeDefaultDescription
childrenReactNode——
openboolean—Controlled open state.
defaultOpenboolean—Initial open state while uncontrolled. Default `false`.
onOpenChange(open: boolean) => void——
sideSide—Preferred side. Flipped to its opposite when there is no room. Default `'bottom'`.
alignAlign—Cross-axis alignment. Default `'start'` - menus line up with their trigger's edge.
offsetnumber—Gap between trigger and menu, px. Default `4`.
paddingnumber—Minimum distance kept from the viewport edges, px. Default `8`.
loopboolean—Wrap arrow navigation past the ends. Default `true`.
typeaheadboolean—Jump to an item by typing its first letters. Default `true`.
containerPortalContainer—Where to portal the menu. Defaults to `document.body`.
idstring—Ids for the trigger/menu pair. Generated when omitted.

Exports

DropdownMenuDropdownMenuCheckboxItemDropdownMenuContentDropdownMenuItemDropdownMenuLabelDropdownMenuSeparatorDropdownMenuTrigger

Rendering