Skip to content

Dropdown

Dropdown menu component that supports hover, click, and right-click triggers, with edge-aware auto-flip positioning.

Basic Usage

Click trigger by default, wrap any element as the dropdown trigger.

vue
<template>
  <u-dropdown>
    <u-button>Click Me</u-button>
    <template #content>
      <u-dropdown-item value="1">Action 1</u-dropdown-item>
      <u-dropdown-item value="2">Action 2</u-dropdown-item>
      <u-dropdown-item value="3">Action 3</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Trigger Modes

Support click, hover, and contextmenu triggers. You can also combine multiple triggers using an array.

Hover Trigger

Dropdown shows on mouse enter and hides on mouse leave (both trigger and content panel).

vue
<template>
  <u-dropdown trigger="hover">
    <u-button color="success">Hover Me</u-button>
    <template #content>
      <u-dropdown-item value="a">Option A</u-dropdown-item>
      <u-dropdown-item value="b">Option B</u-dropdown-item>
      <u-dropdown-item value="c">Option C</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Contextmenu Trigger

Dropdown appears at the mouse position on right-click.

vue
<template>
  <u-dropdown trigger="contextmenu">
    <u-button color="warning">Right Click Me</u-button>
    <template #content>
      <u-dropdown-item value="copy">Copy</u-dropdown-item>
      <u-dropdown-item value="paste">Paste</u-dropdown-item>
      <u-dropdown-item value="cut" color="error">Cut</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Combined Triggers

Use an array to enable multiple triggers simultaneously. When hover opens the dropdown, clicking "pins" it open (mouse leave won't close it), clicking again closes it.

vue
<template>
  <u-dropdown :trigger="['hover', 'click']">
    <u-button color="primary">Hover or Click</u-button>
    <template #content>
      <u-dropdown-item value="1">Hover opens, click pins</u-dropdown-item>
      <u-dropdown-item value="2">Click again to close</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Items Prop

Use the items prop for a declarative approach instead of the content slot.

vue
<template>
  <u-dropdown
    :items="[
      { label: 'New File', value: 'new' },
      { label: 'Open File', value: 'open' },
      { label: 'Save', value: 'save', divided: true },
      { label: 'Save As', value: 'saveas' },
    ]">
    <u-button>File Menu</u-button>
  </u-dropdown>
</template>

Item Colors

Set different color themes for dropdown items via color prop.

vue
<template>
  <u-dropdown trigger="hover">
    <u-button>Color Items</u-button>
    <template #content>
      <u-dropdown-item value="profile" color="primary">Profile</u-dropdown-item>
      <u-dropdown-item value="settings" color="success">Settings</u-dropdown-item>
      <u-dropdown-item value="warning" color="warning">Warning</u-dropdown-item>
      <u-dropdown-item value="logout" color="error" divided>Logout</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Divided & Disabled

Use divided to show a separator line and disabled to disable an item.

vue
<template>
  <u-dropdown>
    <u-button>Menu</u-button>
    <template #content>
      <u-dropdown-item value="1">Action 1</u-dropdown-item>
      <u-dropdown-item value="2">Action 2</u-dropdown-item>
      <u-dropdown-item value="3" disabled>Disabled</u-dropdown-item>
      <u-dropdown-item value="4" divided>Action 4</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Placement

Set popup direction via placement prop. The dropdown automatically flips when it hits the viewport edge.

vue
<template>
  <u-dropdown placement="top-start">
    <u-button>Drop Up</u-button>
    <template #content>
      <u-dropdown-item value="1">Item 1</u-dropdown-item>
      <u-dropdown-item value="2">Item 2</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Custom Width

Set dropdown content width via width prop.

vue
<template>
  <u-dropdown width="200px" trigger="hover">
    <u-button>Wide Dropdown</u-button>
    <template #content>
      <u-dropdown-item value="1">Item with long content</u-dropdown-item>
      <u-dropdown-item value="2">Another item</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Disabled State

Disable the entire dropdown via disabled prop.

vue
<template>
  <u-dropdown disabled>
    <u-button disabled>Disabled Dropdown</u-button>
    <template #content>
      <u-dropdown-item value="1">Should not appear</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

Contextmenu on Area

Right-click anywhere within an area to show the dropdown.

Right-click anywhere in this area
vue
<template>
  <u-dropdown trigger="contextmenu">
    <div class="context-area">Right-click anywhere in this area</div>
    <template #content>
      <u-dropdown-item value="refresh">Refresh</u-dropdown-item>
      <u-dropdown-item value="inspect">Inspect</u-dropdown-item>
      <u-dropdown-item value="source" divided>View Source</u-dropdown-item>
    </template>
  </u-dropdown>
</template>

<style scoped>
.context-area {
  border: 2px dashed var(--u-border);
  padding: 40px;
  text-align: center;
  border-radius: 8px;
}
</style>

UDropdown API

PropertyDescriptionTypeDefault
triggerTrigger mode(s)'hover' | 'click' | 'contextmenu' | Array<...>'click'
disabledWhether to disable the dropdownbooleanfalse
placementPopup placement'bottom' | 'top' | 'bottom-start' | 'top-start''bottom-start'
widthDropdown content widthstring | number-
offsetYVertical offset from trigger (px)number4
delayHover delay (ms)number150
closeOnClickWhether to close on item clickbooleantrue
bgColorBackground colorstring'var(--u-bg)'
itemsDropdown items (declarative)Array<UDropdownItemOption>-

UDropdown Events

EventDescriptionType
visibleChangeTriggered when visibility changes(visible: boolean) => void
selectTriggered when an item is selected(value: string | number) => void

UDropdown Slots

SlotDescription
defaultTrigger element
contentDropdown menu content

UDropdownItem API

PropertyDescriptionTypeDefault
valueItem valuestring | number-
disabledWhether to disablebooleanfalse
colorColor theme'primary' | 'success' | 'warning' | 'error'-
dividedShow top dividerbooleanfalse

UDropdownItem Slots

SlotDescription
defaultItem content