Skip to content

Dropdown

Collapse actions or menus into a dropdown to save interface space.

Basic Usage

Define the dropdown menu content via the dropdown slot. This component supports a Slot Fallback mechanism: when the slot is provided, it completely customizes the menu content; when the slot is not provided, it automatically generates the menu based on the items data.

Dropdown Menu
Basic Usage

Quick Configuration Mode

Quickly configure menu items via the items attribute without using slots.

Quick Config Mode
Quick Configuration Mode

Trigger Mode

Configure to activate on click or hover. Set the trigger attribute to click. Default is hover.

hover to trigger
Dropdown List
click to trigger
Dropdown List
right click to trigger
Dropdown List
Trigger Mode

Split Button

Set the split-button attribute to make the triggering element appear as a button group, with a function button on the left and a dropdown trigger button on the right.

Split Button

Disabled Items

Disable specific menu items by setting the disabled attribute.

Disabled Items

Placement

Set the popup position via the placement attribute.

Placement

Danger Items

By setting danger: true, a menu item will be displayed in a red danger style, commonly used for destructive operations like deletion.

Danger Items

Loading State

Show a loading state via the loading attribute, suitable for scenarios where menu data is loaded asynchronously.

Loading State

Checkable Mode

Enable checkable mode via the checkable attribute, and use it with hide-on-click="false" for multi-selection scenarios.

Checkable Mode

Use in Nuxt

The Dropdown component fully supports SSR rendering for Nuxt 3/4.

Use in Nuxt

SSR Notes:

  • ✅ Perfect support for Server-Side Rendering (SSR), no hydration errors
  • ✅ Supports keyboard navigation
  • ✅ Overlay automatically Teleports to body
  • ✅ Glassmorphism (acrylic) effect adapts automatically

API

PropDescriptionTypeDefault
triggerTrigger mode'hover' | 'click' | 'contextmenu''hover'
placementPopup placementPlacement'bottom'
visibleWhether visible (supports v-model)boolean | nullnull
disabledWhether disabledbooleanfalse
show-afterDelay show time (ms)number0
hide-afterDelay hide time (ms)number150
z-indexOverlay z-indexnumber2000
hide-on-clickWhether to hide after clicking a menu itembooleantrue
itemsMenu item data (Quick Config Mode)DropdownItemData[][]
loadingWhether in loading statebooleanfalse
empty-textEmpty state textstring'No data'
checkableWhether items are checkablebooleanfalse
max-heightMaximum height of the menustring | number''
teleportedWhether to mount to bodybooleantrue
popper-classCustom class name for popperstring''
popper-styleCustom style for popperCSSProperties{}
split-buttonSplit button modebooleanfalse
typeButton type (Split Button mode)'primary' | 'success' | 'warning' | 'danger' | 'info' | ''''
sizeButton size'large' | 'default' | 'small''default'
plainPlain button style (Split Button mode)booleanfalse
show-arrowWhether to show dropdown arrow iconbooleantrue
popper-arrowWhether to show popper arrowbooleantrue
offsetOffset[number, number][0, 8]
loopTab key cycle navigationbooleantrue
tabindexTab indexnumber | string0
PropDescriptionTypeDefault
commandCommand valuestring | number | object''
disabledWhether disabledbooleanfalse
dividedWhether to show dividerbooleanfalse
iconIcon namestring''
dangerWhether it's a danger itembooleanfalse
checkedWhether checked (requires checkable)booleanfalse

Events

Event NameDescriptionCallback Parameters
commandTriggered when menu item is clicked(command: string | number | object)
update:visibleVisibility changed(visible: boolean)
showMenu shown-
hideMenu hidden-
clickClicked trigger (Split Button mode)(event: MouseEvent)

Slots

Slot NameDescription
defaultTrigger element
dropdownDropdown menu content (using DropdownMenu/DropdownItem)
emptyEmpty state content (shown when no items)

Expose

NameDescriptionType
showManually show dropdown menu() => void
hideManually hide dropdown menu() => void
visibleCurrent visibility stateRef<boolean>
typescript
interface DropdownItemData {
  key: string | number
  label: string
  icon?: string
  disabled?: boolean
  divided?: boolean
  class?: string
  children?: DropdownItemData[]
  danger?: boolean    // Red danger style
  checked?: boolean   // Checkable mode
}

Theme Variables (CSS Variables)

All color variables are interfaced with the global theme system, automatically supporting dark mode:

VariableDefault ValueDescription
--yh-dropdown-text-colorvar(--yh-text-color-primary)Menu text color
--yh-dropdown-bg-colorvar(--yh-bg-color-overlay)Popper background color
--yh-dropdown-border-colorvar(--yh-border-color-light)Border/divider color
--yh-dropdown-hover-bgvar(--yh-color-primary-light-9)Menu item hover background
--yh-dropdown-active-bgvar(--yh-color-primary-light-8)Menu item active background
--yh-dropdown-disabled-colorvar(--yh-text-color-placeholder)Disabled item text color
--yh-dropdown-danger-colorvar(--yh-color-danger)Danger item text color
--yh-dropdown-danger-hover-bgvar(--yh-color-danger-light-9)Danger item hover background
--yh-dropdown-shadowvar(--yh-shadow-lg)Popper shadow
--yh-dropdown-radiusvar(--yh-radius-md)Popper corner radius

Tip: The Dropdown component integrates excellent designs from Element Plus, Ant Design, and Naive UI, supporting quick data configuration, split buttons, keyboard navigation, danger item styles, loading states, checkable modes, and more.

Released under the MIT License.