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
openbooleanControlled open state.
defaultOpenbooleanInitial open state while uncontrolled. Default `false`.
onOpenChange(open: boolean) => void
sideSidePreferred side. Flipped to its opposite when there is no room. Default `'bottom'`.
alignAlignCross-axis alignment. Default `'start'` - menus line up with their trigger's edge.
offsetnumberGap between trigger and menu, px. Default `4`.
paddingnumberMinimum distance kept from the viewport edges, px. Default `8`.
loopbooleanWrap arrow navigation past the ends. Default `true`.
typeaheadbooleanJump to an item by typing its first letters. Default `true`.
containerPortalContainerWhere to portal the menu. Defaults to `document.body`.
idstringIds for the trigger/menu pair. Generated when omitted.

Exports

DropdownMenuDropdownMenuCheckboxItemDropdownMenuContentDropdownMenuItemDropdownMenuLabelDropdownMenuSeparatorDropdownMenuTrigger

Rendering