Skip to content

Menu

Provides navigation menus for application structure and routing. It supports vertical and horizontal layouts, collapsible behavior, data-driven rendering, and component-level theme overrides.

Basic Usage

Use default-active to set the initially active menu item.

Basic Usage

Horizontal Menu

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

Horizontal Menu

Collapsed Menu

Set collapse to switch a vertical menu into collapsed mode.

Collapsed Menu

Popper Customization

Set popper-effect, popper-offset, or popper-class to customize popup submenu overlays.

Popper Customization

Data Driven

Use the options prop to generate the menu from data.

Data Driven

External Control

Call the exposed open and close methods through a ref to control submenu state manually.

External Control

Use yh-menu-item-group to group related items.

Menu Grouping

Disabled Menu

Set disabled on menu items or submenus to prevent interaction.

Disabled Menu

Custom Colors

Use background-color, text-color, and active-text-color for simple visual overrides.

Custom Colors

Inverted Style

Set inverted to use the built-in dark style preset.

Inverted Style

Long Menu Content

When menu labels are long, the component can truncate and adapt them to the current layout.

Long Menu Content

Accordion

Set unique-opened to keep only one submenu expanded at a time.

Accordion

Expand Selected Group

Use default-openeds to define which submenus are expanded on initial render.

Expand Selected Group

Custom Node

Use render-label, render-icon, or render-extra for data-driven custom rendering.

Custom Node

Use in Nuxt

YhMenu works in Nuxt 3 after the YH-UI Nuxt module is registered. When router is enabled, use it in client-side routing flows driven by the current route.

Hint: after enabling `router`, the menu highlights items based on the current route path and the item `index`.

Use in Nuxt

SSR Notes

  • Server-rendered menu structure stays aligned with the hydrated client tree.
  • Router integration works with Nuxt navigation after hydration.
  • Collapsed and expanded states stay stable during hydration.

API

Props

PropDescriptionTypeDefault
modeMenu layout mode.YhMenuMode'vertical'
default-activeInitially active menu index.string''
default-openedsInitially opened submenu indices.string[][]
unique-openedWhether only one submenu stays expanded at a time.booleanfalse
menu-triggerTrigger used to open popup submenus.YhMenuTrigger'hover'
collapseWhether vertical mode uses collapsed navigation.booleanfalse
collapse-transitionWhether collapse transition is enabled.booleantrue
routerWhether menu selection is driven by vue-router.booleanfalse
background-colorBackground color override.string''
text-colorText color override.string''
active-text-colorActive text color override.string''
ellipsisWhether long labels in horizontal mode collapse into an overflow menu.booleantrue
popper-z-indexZ-index used by popup submenus.number2000
teleportedWhether popup submenus are teleported to body.booleantrue
gapGap between menu items.number4
ellipsis-iconCustom overflow icon used in horizontal ellipsis mode.string | Component''
popper-offsetPopup submenu offset.number6
popper-effectPopup theme style.'dark' | 'light''light'
close-on-click-outsideWhether popup menus close when clicking outside.booleantrue
popper-classCustom class applied to popup submenus.string''
popper-styleCustom inline style applied to popup submenus.StyleValue''
show-timeoutDelay before a submenu opens.number300
hide-timeoutDelay before a submenu closes.number300
persistentWhether popup submenu DOM stays mounted while hidden.booleantrue
icon-sizeIcon size when the menu is not collapsed.number20
indentIndentation size added per menu level.number32
root-indentFirst-level indentation. Falls back to indent when not provided.numberundefined
expand-allWhether all submenus are expanded by default.booleanfalse
render-extraRender function used to inject extra node content for each option.(option: YhMenuItemData) => VNodeChildundefined
render-iconRender function used to customize option icons.(option: YhMenuItemData) => VNodeChildundefined
render-labelRender function used to customize option labels.(option: YhMenuItemData) => VNodeChildundefined
responsiveWhether horizontal mode automatically collects overflowing items.booleanfalse
valueCurrent selected value, used with v-model:value.string | nullundefined
optionsData-driven menu configuration.YhMenuItemData[][]
invertedWhether to use the built-in inverted style.booleanfalse
key-fieldField name used as the key in data-driven mode.string'key'
label-fieldField name used as the label in data-driven mode.string'label'
theme-overridesComponent-level theme overrides for YhMenu.ComponentThemeVarsundefined
PropDescriptionTypeDefault
indexUnique menu item identifier.stringRequired
routeRoute record or path used in router mode.string | object''
disabledWhether the item is disabled.booleanfalse
labelDisplay text used by data-driven rendering or fallback display.string''
PropDescriptionTypeDefault
titleGroup title text.string''
PropDescriptionTypeDefault
indexUnique submenu identifier.stringRequired
popper-classCustom class applied to the submenu popup.stringundefined
disabledWhether the submenu is disabled.booleanfalse
show-timeoutDelay before the submenu opens. Overrides the parent value when provided.numberundefined
hide-timeoutDelay before the submenu closes. Overrides the parent value when provided.numberundefined
popper-offsetPopup offset. Overrides the parent value when provided.numberundefined
labelDisplay text used by data-driven rendering or fallback display.string''

Events

Event NameDescriptionCallback Parameters
update:valueTriggered when the selected value changes.(value: string) => void
selectTriggered when a menu item is selected.(index: string, indexPath: string[], item: YhMenuItemData | undefined, routeResult?: Promise<void>) => void
openTriggered when a submenu opens.(index: string, indexPath: string[]) => void
closeTriggered when a submenu closes.(index: string, indexPath: string[]) => void

Slots

Slot NameDescriptionParameters
defaultMenu content.-
Slot NameDescriptionParameters
defaultMenu item content.-
Slot NameDescriptionParameters
titleGroup title content.-
defaultGroup content.-
Slot NameDescriptionParameters
titleSubmenu title content.-
defaultSubmenu content.-

Expose

NameDescriptionType
openExpands the specified submenu.(index: string) => void
closeCollapses the specified submenu.(index: string) => void
activeIndexCurrently active menu index.Ref<string>
openedMenusCurrently opened submenu indices.Ref<string[]>

Data structure used by the options prop:

PropDescriptionType
keyUnique identifier, usually the same as index.string
indexAlternative key field used by some data sources.string
labelDisplay text.string
iconIcon name.string
disabledWhether the node is disabled.boolean
childrenChild menu options.YhMenuItemData[]
groupWhether the node represents a grouped block.boolean

Theme Variables

YhMenu supports themeOverrides. The runtime consumes the following component variables:

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)Active item text color.
--yh-menu-hover-bg-colorvar(--yh-color-primary-light-9)Hover background color.
--yh-menu-active-bg-colorvar(--yh-color-primary-light-9)Active item 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-padding20pxBase left and right padding.
--yh-menu-indicator-width3pxActive indicator width.
--yh-menu-indicator-colorvar(--yh-menu-active-text-color)Active indicator color.

Type Exports

NameDescription
YhMenuPropsMenu component props type
YhMenuEmitsMenu component emits type
YhMenuSlotsMenu component slots type
YhMenuExposeMenu component expose type
YhMenuModeMenu mode union
YhMenuTriggerSubmenu trigger union
YhMenuItemDataMenu data type
YhMenuItemPropsMenu item props type
YhMenuItemGroupPropsMenu item group props type
YhSubMenuPropsSubmenu props type
YhMenuInstanceMenu component instance type
YhMenuItemInstanceMenu item instance type
YhMenuItemGroupInstanceMenu item group instance type
YhSubMenuInstanceSubmenu instance type

Inverted Mode

After enabling inverted, the menu switches to a darker visual scheme and reuses the same variables with different values.

  • --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)

Released under the MIT License.