Skip to content

NavView

The NavView component provides a responsive navigation panel that can be expanded or collapsed. It’s commonly used for application navigation, offering a sidebar with menu items that can be organized into categories. The component supports both expanded and compact modes, making it suitable for various screen sizes.

  • Metro UI Core
  • Dom
<div data-role="navview" data-expand-point="md">
<div class="navview-pane">
<!-- Toggle button -->
<div class="logo-container">
<button class="pull-button">
<span class="mif-menu"></span>
</button>
</div>
<!-- Search box -->
<div class="suggest-box">
<input type="text" data-role="input" data-clear-button="false" data-search-button="true">
<button class="holder">
<span class="mif-search"></span>
</button>
</div>
<!-- Navigation menu -->
<ul class="navview-menu">
<li class="item-header">General</li>
<li>
<a href="#">
<span class="icon"><span class="mif-home"></span></span>
<span class="caption">Dashboard</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle">
<span class="icon"><span class="mif-cog"></span></span>
<span class="caption">Settings</span>
</a>
<ul class="navview-menu" data-role="collapse">
<li><a href="#"><span class="caption">Profile</span></a></li>
<li><a href="#"><span class="caption">Security</span></a></li>
</ul>
</li>
</ul>
</div>
<div class="navview-content">
<!-- Your page content goes here -->
<div class="p-4">
<h1>Content Area</h1>
<p>This is the main content area of your application.</p>
</div>
</div>
</div>

The NavView component can automatically switch between expanded and compact modes based on screen size:

<div data-role="navview" data-expand-point="lg">
<!-- NavView content as in the basic example -->
</div>
ParameterTypeDefaultDescription
navViewDeferrednumber0Deferred initialization time in milliseconds
expandPointstringnullMedia query point at which the navview expands (e.g., “md”)
togglestringnullSelector for an external toggle button
animatebooleantrueWhether to animate transitions between expanded and compact states
activeStatebooleantrueWhether to show active state for menu items
initialViewstring”expand”Initial view mode (“expand” or “compact”)
onMenuItemClickfunctionMetro.noopEvent handler for menu item clicks
onPaneClosefunctionMetro.noopEvent handler for when the pane is closed
onBeforePaneClosefunctionMetro.noopEvent handler before the pane is closed
onPaneOpenfunctionMetro.noopEvent handler for when the pane is opened
onBeforePaneOpenfunctionMetro.noopEvent handler before the pane is opened
onNavviewCreatefunctionMetro.noopEvent handler for navview creation

Toggles the NavView between expanded and compact modes.

var navview = Metro.getPlugin('#my-navview', 'nav-view');
navview.toggle();

Forces the NavView into compact mode.

var navview = Metro.getPlugin('#my-navview', 'nav-view');
navview.compact();

Forces the NavView into expanded mode.

var navview = Metro.getPlugin('#my-navview', 'nav-view');
navview.expand();

Returns the current state of the NavView (“expand” or “compact”).

var navview = Metro.getPlugin('#my-navview', 'nav-view');
var currentState = navview.state();

Removes the NavView component and cleans up event handlers.

var navview = Metro.getPlugin('#my-navview', 'nav-view');
navview.destroy();
EventDescription
onMenuItemClickTriggered when a menu item is clicked
onPaneCloseTriggered when the navigation pane is closed
onBeforePaneCloseTriggered before the navigation pane is closed
onPaneOpenTriggered when the navigation pane is opened
onBeforePaneOpenTriggered before the navigation pane is opened
onNavviewCreateTriggered when the navview is created

The NavView component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--navview-pane-width280px280pxWidth of the expanded navigation pane
--navview-pane-width-compact50px50pxWidth of the compact navigation pane
--navview-item-border-radius4px4pxBorder radius for navigation items
--navview-background#f8f8f8#1e1f22Background color for the navview
--navview-color#191919#dbdfe7Text color for the navview
--navview-pane-background#ececec#2b2d30Background color for the navigation pane
--navview-pane-color#191919#dfe1e5Text color for the navigation pane
--navview-item-backgroundtransparenttransparentBackground color for navigation items
--navview-item-color#191919#dfe1e5Text color for navigation items
--navview-item-background-hover#cecece#43454aBackground color for hovered navigation items
--navview-item-color-hover#0a0a0a#ffffffText color for hovered navigation items
--navview-item-background-active#cecece#43454aBackground color for active navigation items
--navview-item-color-active#0a0a0a#ffffffText color for active navigation items
--navview-item-color-disabled#ccc#43454aText color for disabled navigation items
--navview-item-marker-color#468cff#468cffColor for the active item marker
--navview-dropdown-toggle-color#191919#ffffffColor for dropdown toggle indicators
--navview-item-header-color#191919#dfe1e5Color for section headers
--navview-item-header-border-color#cccccc#5d5e60Color for section header borders
--navview-scrollbar-width6px6pxWidth of the scrollbar
--navview-scrollbar-thumb-color#cccccc#5d5e60Color of the scrollbar thumb
--navview-scrollbar-background-color#ececec#2b2d30Background color of the scrollbar
--navview-icon-color#191919#dfe1e5Color for icons
--navview-icon-color-hover#191919#dfe1e5Color for hovered icons
--navview-icon-color-active#191919#dfe1e5Color for active icons
#my-navview {
--navview-pane-width: 320px;
--navview-item-background-hover: #2196f3;
--navview-item-color-hover: #ffffff;
--navview-item-marker-color: #ff4081;
}
  • .navview - Main container class
  • .navview-pane - Container for the navigation pane
  • .navview-content - Container for the content area
  • .navview-menu - Container for menu items
  • .navview-menu-container - Container for the menu with scrolling support
  • .expanded - Applied when the navview is in expanded mode
  • .compacted - Applied when the navview is in compact mode
  • .handmade - Applied when the state was changed manually
  • .animate-panes - Applied when animations are enabled
  • .item-header - Section header in the menu
  • .active - Applied to active menu items
  • .disabled - Applied to disabled menu items
  • .dropdown-toggle - Applied to menu items with dropdown submenus
  • .pull-button - Toggle button for expanding/collapsing the pane
  • .holder - Container for the search icon in compact mode
  • .icon - Container for menu item icons
  • .caption - Container for menu item text
  • .badges - Container for badges
  • .hotkey - Container for keyboard shortcut hints
  1. Use clear, recognizable icons for menu items to improve usability in compact mode
  2. Group related menu items under section headers for better organization
  3. Use badges sparingly to highlight important notifications or counts
  4. Consider using the expandPoint parameter to automatically expand the navigation on larger screens
  5. Provide a toggle button outside the NavView for mobile layouts where screen space is limited