Menu
Used for site headers or sidebars, supporting mode: 'horizontal' | 'vertical', multi-level nested SubMenu fold animations, and dynamic routing pushing with vue-router.
Preview
- 首页
- 管理面板
- 用户管理
- 系统设置
- 关于我们
- 禁用项目
Installation
pnpm dlx brutx-vue@latest add menuUsage
Vertical Mode
<script setup>
import { ref } from 'vue'
import { Menu, MenuItem, SubMenu } from 'brutx-ui-vue'
const active = ref('1')
</script>
<template>
<Menu default-active="1" mode="vertical" @select="idx => active = idx">
<MenuItem index="1">Home</MenuItem>
<SubMenu index="sub-admin" title="Admin Panel">
<MenuItem index="admin-users">Users</MenuItem>
<MenuItem index="admin-settings">Settings</MenuItem>
</SubMenu>
<MenuItem index="3" disabled>Disabled Item</MenuItem>
</Menu>
</template>Horizontal Mode
Set mode="horizontal" to align items horizontally. Under horizontal mode, nested SubMenu lists will display as absolutely-positioned hover dropdowns instead of collapsing inline.
Opening and closing on hover use a short delay. Moving back into the submenu cancels a pending close. Escape, item selection, an outside click, disabling, or unmounting clears pending hover actions.
<script setup>
import { ref } from 'vue'
import { Menu, MenuItem, SubMenu } from 'brutx-ui-vue'
const active = ref('home')
</script>
<template>
<Menu default-active="home" mode="horizontal" @select="idx => active = idx">
<MenuItem index="home">Home</MenuItem>
<SubMenu index="products" title="Products">
<MenuItem index="product-1">Cloud Servers</MenuItem>
<MenuItem index="product-2">Databases</MenuItem>
</SubMenu>
<MenuItem index="about">About</MenuItem>
</Menu>
</template>Routing Mode
Set router to true to auto-push routes on click. If route prop is not explicitly specified on a MenuItem, its index attribute will be used as the target path.
<template>
<Menu router default-active="/home" mode="vertical">
<MenuItem index="/home">Home</MenuItem>
<MenuItem index="/users" :route="{ name: 'UsersList' }">Users</MenuItem>
<MenuItem index="/settings">Settings</MenuItem>
</Menu>
</template>Subcomponents
| Component | Description |
|---|---|
Menu | Root menu component providing context state |
MenuItem | Menu item component |
SubMenu | Submenu component for nested and collapsible contents |
API Reference
Menu
| Name | Type | Default | Description |
|---|---|---|---|
mode | "vertical" | "horizontal" | undefined | "vertical" | Sets the menu item layout direction to horizontal or vertical. |
DetailsDeclared type"vertical" | "horizontal" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/Menu.vue | |||
defaultActive | string | undefined | "" | Sets the index of the initially highlighted menu item and initializes the active item. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/Menu.vue | |||
router | boolean | undefined | false | When enabled, menu items with route navigate through vue-router. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/Menu.vue | |||
class | string | undefined | undefined | CSS classes added to the menu root element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/Menu.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@select | [index: string] | Emits the selected menu item’s index. |
DetailsDeclared type[index: string] Sourcepackages/ui/src/components/menu/Menu.vue | ||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | Menu content, typically MenuItem and SubMenu components. |
DetailsDeclared type{}Sourcepackages/ui/src/components/menu/Menu.vue | ||
MenuItem
| Name | Type | Default | Description |
|---|---|---|---|
indexRequired | string | — | Unique item identifier used for active state and the select event; router mode also uses it to match the current route. |
DetailsDeclared typestring Default value details
Sourcepackages/ui/src/components/menu/MenuItem.vue | |||
disabled | boolean | undefined | false | Disables selection and navigation for this menu item. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/MenuItem.vue | |||
route | string | Record<string, unknown> | undefined | undefined | The path or route object to navigate to when this item is clicked in router mode. |
DetailsDeclared typestring | Record<string, unknown> | undefined Default value details
Sourcepackages/ui/src/components/menu/MenuItem.vue | |||
inset | boolean | undefined | false | Indents the item content to align it with items that include icons. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/MenuItem.vue | |||
class | string | undefined | undefined | CSS classes added to the menu item root element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/MenuItem.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | The menu item label, optionally including an icon. |
DetailsDeclared type{}Sourcepackages/ui/src/components/menu/MenuItem.vue | ||
SubMenu
| Name | Type | Default | Description |
|---|---|---|---|
indexRequired | string | — | Unique identifier for this submenu, used by menu state and nested hierarchy tracking. |
DetailsDeclared typestring Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
title | string | undefined | "" | The submenu trigger title; the title slot provides the rendered content when supplied. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
disabled | boolean | undefined | false | Disables the submenu trigger and prevents it from opening. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
inset | boolean | undefined | false | Indents the submenu trigger content to align it with menu items that include icons. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
class | string | undefined | undefined | CSS classes added to the submenu root container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
triggerClass | string | undefined | undefined | CSS classes added to the submenu title trigger. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/menu/SubMenu.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#title | {} | Customizes the submenu trigger content and takes precedence over the title prop. |
DetailsDeclared type{}Sourcepackages/ui/src/components/menu/SubMenu.vue | ||
#default | {} | Submenu content, which can contain MenuItem or further nested SubMenu components. |
DetailsDeclared type{}Sourcepackages/ui/src/components/menu/SubMenu.vue | ||
Accessibility
- Keyboard Interaction: Supports using
EnterorSpacekeys to selectMenuItemor expand/collapseSubMenu. - ARIA Attributes: The root component automatically sets
role="menubar", and each menu item setsrole="menuitem". The submenu trigger automatically managesaria-haspopup="true"andaria-expandedattributes. - Reduced Motion: Fold animation in vertical mode respects
prefers-reduced-motionsettings and automatically downgrades (if applicable).