Dropdown

free

Dropdown keeps actions and option lists available from a compact trigger.

import Avatar from '@/components/ui/avatar';
import Dropdown from '@/components/ui/dropdown';
import Switcher from '@/components/ui/switcher';
import {

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Dropdown

Examples

Basic

import Dropdown from '@/components/ui/dropdown';

export default function BasicDemo() {
  return (

Custom Toggle

import { PiArchiveFill, PiCopyFill, PiPencilSimpleFill } from 'react-icons/pi'
import Button from '@/components/ui/button';
import Dropdown from '@/components/ui/dropdown';

Trigger

import { PiArchiveFill, PiCopyFill, PiPencilSimpleFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

export default function TriggerDemo() {
import {
    PiArchiveFill,
    PiEnvelopeSimpleFill,
    PiFolderOpenFill,

Placement

import { PiArchiveFill, PiCopyFill, PiPencilSimpleFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

const DropdownItems = () => (

Active Item

import { PiSortAscendingFill, PiSortDescendingFill, PiTextAaFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

export default function ActiveItemDemo() {

Disabled

import { PiArchiveFill, PiCopyFill, PiPencilSimpleFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

export default function DisabledDemo() {

Item Variants

import { ReactNode } from 'react';
import {
    PiBuildingFill,
    PiCreditCardFill,

Context Menu

import { PiCopyFill, PiPencilSimpleFill, PiTrashFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

export default function ContextMenuDemo() {
import { PiArrowRightFill } from 'react-icons/pi'
import Dropdown from '@/components/ui/dropdown';

export default function LinkDemo() {

API

Dropdown is a compound component: the root trigger, Dropdown.Item, Dropdown.Menu for submenus, and Dropdown.ContextMenu for right-click menus.

PropDescriptionTypeDefault
activeKeyMatches a Dropdown.Item's eventKey to mark it active.string-
disabledPrevents the dropdown from opening.boolean-
menuClassClass names applied to the menu surface.string-
onOpenCalled when the open state changes.DropdownOpenChangeHandler-
onSelectCalled when a Dropdown.Item inside is selected.DropdownSelectHandler-
placementSide and alignment the menu opens from, relative to the trigger.DropdownPlacement'bottom-start'
renderTitleCustom trigger content, replacing the default toggle.ReactNode-
titleLabel rendered in the default toggle.string | ReactNode-
toggleClassNameClass names applied to the trigger element.string-
triggerHow the menu opens: on click, hover, or right-click.'click' | 'hover' | 'rightClick''click'
...nativePropsNative props applied to the trigger element.ComponentProps<'div'>-
PropDescriptionTypeDefault
activeMarks the item as active, independent of activeKey matching.boolean-
asElementElement or component the item renders as.ElementType'li'
closeOnClickCloses the dropdown after this item is selected.booleantrue
disabledPrevents interaction with this item.boolean-
eventKeyValue passed to onSelect and matched against activeKey.string-
onClickCalled when the item is clicked.(e: SyntheticEvent) => void-
onFocusCalled when the item receives focus.(e: SyntheticEvent) => void-
onSelectCalled with the item's eventKey when selected.DropdownSelectHandler-
variantVisual role of the item.DropdownItemVariant'default'
...nativePropsNative props applied to the rendered element.ComponentProps<'li'>-

Renders a nested submenu. Used as a child of Dropdown or another Dropdown.Menu.

PropDescriptionTypeDefault
eventKeyValue matched against the parent's activeKey to highlight this submenu.string-
menuClassClass names applied to the submenu surface.string-
onOpenCalled when the submenu's open state changes.DropdownOpenChangeHandler-
placementSide the submenu opens from, relative to its parent item.DropdownPlacement'right-start'
renderTitleCustom content replacing the default submenu trigger row.ReactNode-
titleLabel rendered as the submenu's trigger row.string | ReactNode-

Renders its areaContent inside a region that opens the menu on right-click, instead of a click-to-open toggle.

PropDescriptionTypeDefault
activeKeyMatches a Dropdown.Item's eventKey to mark it active.string-
areaClassClass names applied to the right-click area.string-
areaContentContent rendered inside the right-click area. Required.ReactNode-
areaRefRef forwarded to the right-click area element.Ref<HTMLDivElement>-
childrenDropdown.Item / Dropdown.Menu elements rendered as the menu content.ReactNode-
disabledPrevents the menu from opening.boolean-
menuClassClass names applied to the menu surface.string-
onOpenCalled when the open state changes — right-click (or openAt/handleDropdownOpen) to open, and Escape, outside click, or handleDropdownClose to close.DropdownOpenChangeHandler-
placementSide and alignment the menu opens from, relative to the cursor.DropdownPlacement'bottom-start'
refImperative handle for opening and closing the menu programmatically.Ref<DropdownContextMenuRef>-

Types

type DropdownPlacement =
  | 'top'
  | 'top-start'
  | 'top-end'
  | 'right'
  | 'right-start'
  | 'right-end'
  | 'bottom'
  | 'bottom-start'
  | 'bottom-end'
  | 'left'
  | 'left-start'
  | 'left-end';
type DropdownItemVariant = 'default' | 'header' | 'divider' | 'custom';
type DropdownOpenChangeHandler = (open: boolean) => void;
type DropdownSelectHandler = (eventKey: string, e: SyntheticEvent) => void;
type DropdownContextMenuRef = {
  openAt: (x: number, y: number) => void;
  handleDropdownOpen: () => void;
  handleDropdownClose: () => void;
};