Skip to content

Menu ​

Brief Introduction ​

The Menu navigation component provides sidebar and top navigation functionality. mengyue-components has encapsulated it and performed vitest testing. You can use <MYMenu></MYMenu> or <MYMenu /> to implement a navigation menu component.

Basic Usage ​

Vertical Menu ​

Default vertical menu, supports multi-level nesting.

Code Demo
  • 🏠 Home
  • 📊 Statistics
  • 🔒 Disabled Menu
展开代码

Horizontal Menu ​

Use the mode property set to horizontal to create a horizontal menu.

Code Demo
  • Home
  • Products
  • About Us
展开代码

Custom Colors ​

Use the backgroundColor, textColor, and activeTextColor properties to customize menu colors.

Code Demo
  • 🌟 Golden Theme
  • 🎨 Color Customization
展开代码

Unique Opened Menu ​

Use the unique-opened property to ensure only one submenu can be expanded at a time.

Code Demo
  • 📁 Document Management
展开代码

Hover Trigger ​

Use the trigger property set to hover to trigger submenu expansion on hover.

Code Demo
  • Home
  • Contact Us
展开代码

API Reference ​

ParameterDescriptionTypeOptionsDefault
default-activeIndex of the default active menustring—''
modeMenu modestringvertical / horizontalvertical
collapseWhether to collapse the menu horizontallyboolean—false
background-colorMenu background colorstring—#2f3b46
text-colorMenu text colorstring—#bfcbd9
active-text-colorText color of the active menustring—#409EFF
triggerTrigger method for opening submenustringclick / hoverclick
unique-openedWhether to keep only one submenu expandedboolean—false
default-openedsArray of default opened sub-menu indicesarray—[]
collapse-transitionWhether to enable collapse animationboolean—true
ParameterDescriptionTypeOptionsDefault
indexUnique identifierstring—Required
disabledWhether disabledboolean—false
ParameterDescriptionTypeOptionsDefault
indexUnique identifierstring—Required
triggerTrigger method for opening submenustringclick / hoverInherits from Menu
teleportedWhether to use teleportboolean—false

Events ​

Event NameDescriptionParameters
selectMenu activation callbackindex: string, indexPath: string[]
openSub-menu expand callbackindex: string, indexPath: string[]
closeSub-menu collapse callbackindex: string, indexPath: string[]

Type Definitions ​

typescript
interface MenuProps {
  defaultActive?: string;
  mode?: 'vertical' | 'horizontal';
  collapse?: boolean;
  backgroundColor?: string;
  textColor?: string;
  activeTextColor?: string;
  trigger?: 'click' | 'hover';
  uniqueOpened?: boolean;
  defaultOpeneds?: string[];
  collapseTransition?: boolean;
}

interface MenuItemProps {
  index: string;
  disabled?: boolean;
}

interface SubMenuProps {
  index: string;
  trigger?: 'click' | 'hover';
  teleported?: boolean;
}

Released under the MIT License.