The MenuList component provides a flexible navigation menu with multiple variants and styling options. It's designed to display lists of menu items with support for active states, icons, and different visual styles.
import { MenuList } from '@dashflowx/core';export default function MenuListExample() {const menuItems = [{ id: '1', title: 'Dashboard', path: '/dashboard', active: true },{ id: '2', title: 'Analytics', path: '/analytics', active: false },{ id: '3', title: 'Settings', path: '/settings', active: false }];return (<MenuListmenuArrays={menuItems}variant="basic"library="next"type="a"/>);}
Preview:
Simple list-style menu with clean design.
<MenuListvariant="basic"menuArrays={menuItems}showText={true}showIcon={true}/>
Preview:
Enhanced menu with better spacing and visual hierarchy.
<MenuListvariant="one"menuArrays={menuItems}showText={true}showIcon={true}/>
Preview:
Card-style menu with header and structured layout.
<MenuListvariant="two"menuArrays={menuItems}showText={true}showIcon={true}/>
Preview:
| Prop | Type | Default | Description |
|---|---|---|---|
menuArrays | MenuItem[] | - | Array of menu items to display |
variant | 'basic' | 'one' | 'two' | 'basic' | Visual style variant of the menu |
library | 'react' | 'next' | 'next' | Library type for link handling |
type | string | 'a' | Link element type |
className | string | '' | Additional CSS classes |
showText | boolean | true | Whether to show menu item text |
showIcon | boolean | true | Whether to show menu item icons |
tooltipClassName | string | '' | CSS classes for tooltips |
navClassName | string | '' | CSS classes for navigation wrapper |
interface MenuItem {id: string; // Unique identifiertitle: string; // Display textpath: string; // Link pathactive: boolean; // Active statemenuIcon?: React.ReactNode; // Optional icon}
const navigationItems = [{id: '1',title: 'Dashboard',path: '/dashboard',active: true,menuIcon: '🏠'},{id: '2',title: 'Analytics',path: '/analytics',active: false,menuIcon: '📊'},{id: '3',title: 'Settings',path: '/settings',active: false,menuIcon: '⚙️'}];<MenuListvariant="one"menuArrays={navigationItems}showIcon={true}showText={true}/>
Preview:
<MenuListvariant="basic"menuArrays={menuItems}showIcon={false}showText={true}className="text-sm"/>
Preview:
<MenuListvariant="two"menuArrays={menuItems}showIcon={true}showText={true}className="w-64"/>
Preview:
<MenuListvariant="basic"menuArrays={menuItems}className="bg-gray-50 rounded-lg p-4"showIcon={true}showText={true}/>
// For React Router<MenuListlibrary="react"type="Link"menuArrays={menuItems}/>// For Next.js<MenuListlibrary="next"type="a"menuArrays={menuItems}/>
Always ensure only one menu item has active: true at a time.
// ✅ Good - Single active itemconst menuItems = [{ id: '1', title: 'Home', path: '/', active: true },{ id: '2', title: 'About', path: '/about', active: false },{ id: '3', title: 'Contact', path: '/contact', active: false }];// ❌ Bad - Multiple active itemsconst menuItems = [{ id: '1', title: 'Home', path: '/', active: true },{ id: '2', title: 'About', path: '/about', active: true }, // Should be false{ id: '3', title: 'Contact', path: '/contact', active: false }];
Use consistent and meaningful icons for better UX.
// ✅ Good - Consistent icon styleconst menuItems = [{ id: '1', title: 'Dashboard', path: '/dashboard', active: true, menuIcon: '🏠' },{ id: '2', title: 'Analytics', path: '/analytics', active: false, menuIcon: '📊' },{ id: '3', title: 'Settings', path: '/settings', active: false, menuIcon: '⚙️' }];
Choose variants based on your design needs.
// ✅ Good - Variant selection<MenuList variant="basic" /> // For simple lists<MenuList variant="one" /> // For enhanced navigation<MenuList variant="two" /> // For card-style menus
The MenuList component includes accessibility features:
- Semantic HTML: Uses proper
<nav>and<ul>elements - Keyboard Navigation: Supports keyboard navigation
- Screen Reader Support: Proper ARIA labels and roles
- Focus Management: Clear focus indicators
- Color Contrast: Meets WCAG guidelines
- Memoization: Use
React.memofor large menu lists - Lazy Loading: Implement lazy loading for dynamic menu items
- Icon Optimization: Use optimized icon components
- CSS Classes: Leverage Tailwind CSS for consistent styling
- NavigationMenu: For complex navigation structures
- Menubar: For horizontal menu bars
- Breadcrumb: For hierarchical navigation
- Tabs: For tabbed navigation interfaces
