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:

  • Fully supports Server-Side Rendering (SSR) in Nuxt 3/4 projects
  • Keyboard interaction is built in for trigger handling and visibility control
  • The overlay is teleported to body by default and can be disabled with teleported
  • Empty and loading states both participate in the locale pipeline at runtime

API

Props

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)YhDropdownItemData[][]
loadingWhether in loading statebooleanfalse
empty-textEmpty state textstringundefined
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
theme-overridesComponent-level theme overridesComponentThemeVarsundefined

Types

PropDescriptionTypeDefault
commandCommand valuestring | number | object''
disabledWhether disabledbooleanfalse
dividedWhether to show dividerbooleanfalse
iconIcon namestring''
dangerWhether it's a danger itembooleanfalse
checkedWhether checked (requires checkable)booleanfalse
theme-overridesComponent-level theme overridesComponentThemeVarsundefined
PropDescriptionTypeDefault
theme-overridesComponent-level theme overridesComponentThemeVarsundefined

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 YhDropdownItemData {
  key: string | number
  label: string
  icon?: string
  disabled?: boolean
  divided?: boolean
  class?: string
  children?: YhDropdownItemData[]
  danger?: boolean
  checked?: boolean
}

Theme Variables

Dropdown, YhDropdownItem, and YhDropdownMenu all accept themeOverrides. The component consumes shared theme tokens directly in source, so the runtime styling is mainly controlled through the following tokens:

VariableDescription
--yh-text-color-primaryPrimary text color for menu items
--yh-text-color-secondaryLoading text color
--yh-text-color-placeholderDisabled and empty state text color
--yh-bg-color-overlayDropdown popup background
--yh-border-color-lightDivider color
--yh-color-primaryActive/checkable item color
--yh-color-primary-light-9Hover background
--yh-color-primary-light-8Active background
--yh-color-dangerDanger item color
--yh-color-danger-light-9Danger hover background
--yh-color-danger-light-8Danger active background
--yh-radius-mdItem corner radius
--yh-radius-lgPopup corner radius
--yh-shadow-lgPopup shadow
--yh-font-size-baseTrigger and menu text size

Type Exports

NameDescription
YhDropdownPropsProps type for YhDropdown
YhDropdownEmitsEmits type for YhDropdown
YhDropdownSlotsSlots type for YhDropdown
YhDropdownExposeExpose type for YhDropdown
YhDropdownTriggerTrigger union type
YhDropdownItemDataDropdown item data type
YhDropdownItemPropsProps type for YhDropdownItem
YhDropdownMenuPropsProps type for YhDropdownMenu
YhDropdownInstancePublic instance type for YhDropdown
YhDropdownItemInstancePublic instance type for YhDropdownItem
YhDropdownMenuInstancePublic instance type for YhDropdownMenu

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.