Skip to Content
NarakUI

Dropdown Menu

A dropdown menu component for displaying a list of actions or options.

Actions

A row or card menu behind an icon button. Give an icon-only trigger an aria-label, and use start for item icons.

Groups, options, and submenus

Label titles a group. RadioGroup picks one value; CheckboxItem toggles several and shows an "only" shortcut on hover. Call event.preventDefault() in onSelect to keep the menu open while toggling. Sub nests a menu.

Button trigger

buttonWithChevron renders a small button with a chevron that flips while the menu is open. Pass the label as children and iconStart for an icon.

Installation

pnpm dlx shadcn@latest add @narakui/dropdown-menu

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/dropdown-menu.json.

Usage

import { Dropdown } from '@/components/ui/dropdown-menu';

<Dropdown.Root>
  <Dropdown.Trigger asChild>
    <Button>Open menu</Button>
  </Dropdown.Trigger>
  <Dropdown.Content>
    <Dropdown.Item>Item 1</Dropdown.Item>
    <Dropdown.Item>Item 2</Dropdown.Item>
  </Dropdown.Content>
</Dropdown.Root>

Dropdown.Root is non-modal by default. Inside a drawer or a modal dialog it is always modal, so a long menu can still scroll.

Use Dropdown.RadioGroup and Dropdown.RadioItem when the rows are alternatives and exactly one is chosen. The chosen row shows a check.

<Dropdown.RadioGroup value={sort} onValueChange={setSort}>
  <Dropdown.RadioItem value="newest">Newest</Dropdown.RadioItem>
  <Dropdown.RadioItem value="oldest">Oldest</Dropdown.RadioItem>
</Dropdown.RadioGroup>

Nest a submenu with Dropdown.Sub, Dropdown.SubTrigger and Dropdown.SubContent.

<Dropdown.Sub>
  <Dropdown.SubTrigger startIcon="share">Share</Dropdown.SubTrigger>
  <Dropdown.SubContent>
    <Dropdown.Item start="link">Copy link</Dropdown.Item>
  </Dropdown.SubContent>
</Dropdown.Sub>
PropTypeDefaultDescription
openboolean—Controlled open state of the dropdown
defaultOpenbooleanfalseInitial open state when uncontrolled
onOpenChange(open: boolean) => void—Called when the open state changes
modalbooleanfalseTraps focus and blocks the page behind the menu. Always true inside a drawer or a modal dialog
PropTypeDefaultDescription
asChildbooleanfalseMerges the trigger behavior into its child element
buttonWithChevronbooleanfalseRenders the trigger as a Button with a chevron that flips while the menu is open
fullSizeAndButtonWithChevronToTheRightbooleanfalseRenders a Button with a truncated label on the left and the chevron on the right
iconStartIconValue—Icon before the label in the two Button variants
size'micro' | 'small' | 'regular' | 'large'—Button size in the two Button variants. buttonWithChevron defaults to small
PropTypeDefaultDescription
side'top' | 'right' | 'bottom' | 'left''bottom'Preferred side of the trigger to render against
align'start' | 'center' | 'end''center'Alignment of the content relative to the trigger
sideOffsetnumber10Distance in pixels from the trigger
alignOffsetnumber0Offset in pixels along the alignment axis
sizenumber249Minimum width of the menu in pixels
fullWidthbooleanfalseUses the trigger's width as the minimum width instead of size
withPortalbooleantrueWhether to render content in a portal
portalContainerHTMLElement—Container element for the portal
pinnedBottomReactNode—Content pinned to the bottom of the menu, with the rows above it scrolling
restoreTriggerFocusbooleanfalseReturn focus to the trigger when the menu closes, except after an outside click
submenusGrowUpwardbooleanfalseOpens every nested submenu upward, so its last row lines up with the row that opened it
PropTypeDefaultDescription
startIconValue—Icon name, descriptor, or node shown before the label
endIconValue—Icon name, descriptor, or node shown at the end of the row
onSelect(event: Event) => void—Called when the item is chosen. Call event.preventDefault() to keep the menu open
hrefstring—Renders the item as a link
targetstring—Target attribute for link items
relstring—Rel attribute for link items
disabledbooleanfalseWhether the item is disabled
disabledReasonstring—Tooltip on a disabled item that explains why it is disabled
disableTooltipbooleanfalseTurns off the tooltip that shows a truncated label in full
tooltipSide'top' | 'right' | 'bottom' | 'left''right'Side of the truncated-label tooltip
PropTypeDefaultDescription
checkedboolean | 'indeterminate'falseWhether the row is checked
onCheckedChange(checked: boolean) => void—Called when the row is toggled
showOnlyButtonbooleantrueShows an 'only' button on hover
onOnlyClick() => void—Called when the 'only' button is clicked
childrenClassNamestring—Classes for the label wrapper. Replaces the default truncate
PropTypeDefaultDescription
valuestring—On RadioGroup, the chosen value. On RadioItem, the value this row stands for (required)
onValueChange(value: string) => void—RadioGroup only. Called with the value of the chosen row
startIconValue—RadioItem only. Icon name, descriptor, or node shown before the label
disableTooltipbooleanfalseRadioItem only. Turns off the tooltip that shows a truncated label in full
tooltipSide'top' | 'right' | 'bottom' | 'left''right'RadioItem only. Side of the truncated-label tooltip
childrenClassNamestring—RadioItem only. Classes for the label
PropTypeDefaultDescription
Dropdown.Sub{ open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void }—Container for a nested submenu
startIconIconValue—SubTrigger only. Icon shown before the label
hideChevronbooleanfalseSubTrigger only. Hides the trailing chevron
pinnedBottomReactNode—SubContent only. Content pinned to the bottom of the submenu, with the rows above it scrolling
sideOffsetnumber0SubContent only. Distance in pixels from the sub-trigger
alignOffsetnumber-4SubContent only. Offset in pixels along the alignment axis

Other Parts

PartTypeDescription
Dropdown.LabelComponentPropsWithoutRef<typeof Label>Heading for a group of rows. Takes size: 'small' or 'medium' (default)
Dropdown.GroupComponentPropsWithoutRef<typeof Group>Groups related rows
Dropdown.SeparatorComponentPropsWithoutRef<typeof Separator>Line between rows
Dropdown.ShortcutKbdPropsKeyboard shortcut badge pinned to the end of a row
Dropdown.PortalComponentPropsWithoutRef<typeof Portal>The portal Content renders into unless withPortal is false