Skip to content

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

Preview
Menu 导航菜单

Installation

pnpm dlx brutx-vue@latest add menu

Usage

Vertical Mode

vue
<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.

vue
<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.

vue
<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

ComponentDescription
MenuRoot menu component providing context state
MenuItemMenu item component
SubMenuSubmenu component for nested and collapsible contents

Props

PropTypeDefaultDescription
mode'horizontal' | 'vertical''vertical'Alignment mode
defaultActivestring''Key of the default active menu item
routerbooleanfalseEnable vue-router redirection modes
classstringCustom class list
PropTypeDefaultDescription
indexstringRequired, unique key identifying the menu item
disabledbooleanfalseDisable item interaction
routestring | objectTarget route path or object
classstringCustom class list
PropTypeDefaultDescription
indexstringRequired, unique key identifying the sub-menu
titlestring''Title label (prioritized below title slot)
disabledbooleanfalseDisable entire sub-menu interaction
triggerClassstringCustom header trigger class list
classstringCustom wrapper class list

Events

EventParametersDescription
selectstringEmitted when a menu item is clicked and selected, parameter is the active index

Slots

SlotScopeDescription
defaultNested submenu items (e.g. MenuItem or nested SubMenu)
titleCustom header title trigger elements

Accessibility

  • Keyboard Interaction: Supports using Enter or Space keys to select MenuItem or expand/collapse SubMenu.
  • ARIA Attributes: The root component automatically sets role="menubar", and each menu item sets role="menuitem". The submenu trigger automatically manages aria-haspopup="true" and aria-expanded attributes.
  • Reduced Motion: Fold animation in vertical mode respects prefers-reduced-motion settings and automatically downgrades (if applicable).

Brute force builds.