Skip to content

Menu

Providing a navigation menu for users, supporting both vertical and horizontal modes.

Basic Usage

Vertical menu, use default-active to set the default active menu item.

Basic Usage

Horizontal Menu

Set mode="horizontal" to create a horizontal navigation menu.

Horizontal Menu

Collapsed Menu

Switch the collapsed state of the menu via the collapse attribute.

Collapsed Menu

Popper Customization

Set the popper theme via popper-effect and adjust the offset via popper-offset.

Popper Customization

Data Driven

Directly generate the menu from array data via the options attribute.

Data Driven

External Control

Manually control the menu state by calling exposed methods via ref.

External Control

Group menu items using yh-menu-item-group.

Menu Grouping

Disabled Menu

Disable menu items or submenus via the disabled attribute.

Disabled Menu

Custom Colors

Customize menu colors via background-color, text-color, and active-text-color.

Custom Colors

Inverted Style

Quickly toggle the dark inverted theme via the inverted attribute.

Inverted Style

Long Menu Content

When the text content of menu items or submenus is too long, an ellipsis will be automatically shown and it will adapt to the layout.

Long Menu Content

Accordion

Use the unique-opened attribute to only keep one submenu expanded at a time.

Accordion

Expand Selected Group

Use default-openeds to preset an array of submenu identifiers that need to be expanded initially.

Expand Selected Group

Custom Node

Batch deep customization of menu node display content through render functions like render-label or slots.

Custom Node

Use in Nuxt

The Menu component supports the router attribute and can be used with Nuxt's routing system.

Hint: After setting the router attribute, the menu will automatically activate based on the matching of the current route path and index.

Use in Nuxt

SSR Notes:

  • ✅ Perfect support for Server-Side Rendering (SSR) with no hydration errors.
  • ✅ Supports vue-router integration.
  • ✅ Supports collapse animations.
  • ✅ Full keyboard navigation support.

API

PropDescriptionTypeDefault
modeMenu mode'vertical' | 'horizontal''vertical'
default-activeIndex of the currently active menustring''
default-openedsArray of indices for currently open sub-menusstring[][]
expand-allWhether to expand all menusbooleanfalse
unique-openedWhether to only keep one submenu expandedbooleanfalse
menu-triggerSub-menu opening trigger method (valid in Popup mode)'hover' | 'click''hover'
collapseWhether to enable collapsed mode (vertical mode only)booleanfalse
collapse-transitionWhether collapse animation is enabledbooleantrue
routerWhether to use vue-router modebooleanfalse
root-indentIndentation for the first level of the menu, defaults to indentnumber
render-extraBatch processing of extra menu part rendering (VNode)Function
render-iconBatch processing of menu icon rendering (VNode)Function
render-labelBatch processing of menu label rendering (VNode)Function
responsiveWhether to automatically collapse overflowing menus (horizontal mode)booleanfalse
valueCurrent selected value of the menu (supports v-model)string | null
optionsMenu configuration entries, supports generating menu from dataMenuItemData[][]
background-colorBackground colorstring''
text-colorText colorstring''
active-text-colorActive item text colorstring''
ellipsisWhether to enable ellipsis mode (horizontal mode)booleantrue
popper-z-indexZ-index for sub-menu poppernumber2000
teleportedWhether to teleport the popup menu to bodybooleantrue
gapMenu item gapnumber4
icon-sizeIcon size when menu is not collapsednumber20
indentIndentation per menu levelnumber32
invertedWhether to use inverted style (dark background)booleanfalse
key-fieldField name for key in data sourcestring'key'
label-fieldField name for label in data sourcestring'label'
ellipsis-iconCustom ellipsis icon (horizontal mode)string | Component
popper-offsetOffset for the poppernumber6
popper-effectTooltip theme'dark' | 'light''light'
close-on-click-outsideWhether to collapse menu when clicking outsidebooleantrue
popper-classCustom class for the popup menustring''
popper-styleCustom style for the popup menustring | object''
show-timeoutDelay before menu appearancenumber300
hide-timeoutDelay before menu disappearancenumber300
persistentWhether to keep sub-menu DOM when hiddenbooleantrue
PropDescriptionTypeDefault
indexUnique identifierstring— (Required)
labelDisplay textstring''
routevue-router route objectstring | object''
disabledWhether disabledbooleanfalse
PropDescriptionTypeDefault
titleGroup titlestring''
PropDescriptionTypeDefault
indexUnique identifierstring— (Required)
labelDisplay textstring''
popper-classCustom class for the popup menustring''
disabledWhether disabledbooleanfalse
show-timeoutDelay for expanding/collapsingnumber300
hide-timeoutDelay for collapsingnumber300
popper-offsetOffset for the poppernumber6

Events

Event NameDescriptionCallback Parameters
selectCallback for menu activation(index: string, indexPath: string[], item: MenuItemData | undefined, routeResult?: Promise<void>)
openCallback for sub-menu expansion(index: string, indexPath: string[])
closeCallback for sub-menu collapse(index: string, indexPath: string[])
update:valueCallback when value changes (supports v-model)(value: string) => void

Slots

Slot NameDescriptionComponent
defaultMenu contentMenu
defaultMenu item contentMenuItem
titleGroup titleMenuItemGroup
defaultGroup contentMenuItemGroup
titleSub-menu titleSubMenu
defaultSub-menu contentSubMenu

Expose

NameDescriptionType
openExpand specified sub-menu(index: string) => void
closeCollapse specified sub-menu(index: string) => void
activeIndexCurrently active itemRef<string>
openedMenusCurrently expanded sub-menusRef<string[]>

Data structure for options prop:

PropDescriptionType
keyUnique identifier (same as index)string
indexUnique identifier (same as key)string
labelDisplay textstring
iconIcon namestring
disabledWhether disabledboolean
childrenSub-menu dataMenuItemData[]
groupWhether it is a group itemboolean

Theme Variables

All color variables are integrated with the global theme system and support dark mode:

VariableDefaultDescription
--yh-menu-bg-colorvar(--yh-bg-color)Menu background color
--yh-menu-text-colorvar(--yh-text-color-primary)Menu text color
--yh-menu-active-text-colorvar(--yh-color-primary)Text color in active state
--yh-menu-hover-bg-colorvar(--yh-color-primary-light-9)Hover background color
--yh-menu-active-bg-colorvar(--yh-color-primary-light-9)Active background color
--yh-menu-border-colorvar(--yh-border-color-light)Menu border color
--yh-menu-item-height50pxMenu item height
--yh-menu-icon-size18pxMenu icon size
--yh-menu-base-padding20pxMenu base padding
--yh-menu-indicator-width3pxIndicator width
--yh-menu-indicator-colorvar(--yh-menu-active-text-color)Indicator color

Inverted Mode

After enabling the inverted attribute, the menu automatically switches to a dark theme, using the following override variables:

  • --yh-menu-bg-color: var(--yh-bg-color-overlay-dark)
  • --yh-menu-text-color: var(--yh-text-color-secondary)
  • --yh-menu-hover-bg-color: var(--yh-fill-color-dark)

Note: The Menu component combines the best designs of Element Plus, Ant Design, and Naive UI, supporting rich features like vertical/horizontal modes, collapse, grouping, and vue-router integration.

Released under the MIT License.