Skip to content

Page Control

The Page Control component provides a tabbed interface for organizing content into separate tabs. It supports tab creation, activation, closing, and renaming, with features like overflow handling, context menus, and reference control.

  • Metro UI Core
  • DOM library
<ul data-role="page-control">
<li class="active">Home</li>
<li>Profile</li>
<li>Settings</li>
</ul>
<ul data-role="page-control">
<li class="active" data-icon="mif-home">Home</li>
<li data-icon="mif-user">Profile</li>
<li data-icon="mif-cog" data-close="false">Settings</li>
</ul>
<ul data-role="page-control" data-ref-control="true">
<li class="active" data-ref="#home-content">Home</li>
<li data-ref="#profile-content">Profile</li>
<li data-ref="#settings-content">Settings</li>
</ul>
<div id="home-content">Home content here</div>
<div id="profile-content" style="display: none;">Profile content here</div>
<div id="settings-content" style="display: none;">Settings content here</div>
// Create a page control programmatically
const pageControl = Metro.makePlugin("#container", "page-control", {
tabsPosition: "center",
appendButton: true,
defaultNewTabTitle: "New Tab"
});
// Add tabs
pageControl.addTab({
caption: "Home",
icon: "mif-home",
canClose: false
});

The Page Control component accepts the following configuration options:

ParameterTypeDefaultDescription
appendButtonbooleantrueShow button to add new tabs
tabsPositionstring"left"Position of tabs (“left”, “center”, “right”)
customButtonsarraynullCustom buttons for the control
activateNewTabbooleantrueActivate newly created tabs
defaultNewTabTitlestring"New File"Default title for new tabs
defaultNewCanClosebooleantrueWhether new tabs can be closed by default
defaultNewTabIconstring""Default icon class for new tabs
defaultNewTabImagestring""Default image URL for new tabs
defaultNewTabPositionstring"before"Where to add new tabs (“before”, “after”)
appendActionsfunctionnullFunction that returns an array of actions for the append button menu
tabsActionsfunctionnullFunction that returns an array of actions for the tabs menu
tabActionsfunctionnullFunction that returns an array of actions for individual tab menus
refControlbooleanfalseControl visibility of referenced elements based on active tab
EventDescription
onAppendButtonClickTriggered when the append button is clicked
onTabCreateTriggered when a tab is created
onTabActivateTriggered when a tab is activated
onTabDeactivateTriggered when a tab is deactivated
onTabBeforeCloseTriggered before a tab is closed (return false to prevent closing)
onTabCloseTriggered when a tab is closed
onTabRenameTriggered when a tab is renamed
onTabPropChangeTriggered when a tab property is changed
onTabOrganizedTriggered when tabs are reorganized

The Page Control component provides the following methods:

MethodParametersDescription
createTab(options)options: objectCreates a new tab with the specified options
addTab(options, insert)options: object, insert: stringAdds a new tab with the specified options and position
activateTab(tab)tab: elementActivates the specified tab
closeTab(tab, reorg)tab: element, reorg: booleanCloses the specified tab
closeAll()-Closes all tabs
closeInactiveTabs()-Closes all inactive tabs
closeOtherTabs(tab)tab: elementCloses all tabs except the specified one
closeTabsOnTheLeft(tab)tab: elementCloses all tabs to the left of the specified tab
closeTabsOnTheRight(tab)tab: elementCloses all tabs to the right of the specified tab
getActiveTab()-Gets the currently active tab
getActiveTabIndex()-Gets the index of the active tab
getTabByIndex(index)index: numberGets a tab by its index
getTabByTitle(caption)caption: stringGets a tab by its caption/title
setupTab(tab, prop, val)tab: element, prop: string, val: anyUpdates a tab’s property
renameTab(tab)tab: elementOpens a dialog to rename the specified tab
organizeTabs()-Reorganizes tabs to fit the available space

When using the createTab() or addTab() methods, you can pass the following options:

OptionTypeDescription
captionstringTab title/caption
iconstringCSS class for the tab icon
imagestringURL for the tab image
canClosebooleanWhether the tab can be closed
hasMenubooleanWhether the tab has a context menu
dataanyCustom data associated with the tab
refstringReference to an element controlled by the tab
// Get the page control instance
const pageControl = Metro.getPlugin("#myPageControl", "page-control");
// Add a new tab
const newTab = pageControl.addTab({
caption: "New Tab",
icon: "mif-file",
canClose: true
});
// Activate a tab
pageControl.activateTab(newTab);
// Close all inactive tabs
pageControl.closeInactiveTabs();

The Page Control component can be styled using the following CSS variables:

VariableDefault (Light)Dark ModeDescription
--page-control-background#ffffff#222222Background color of the page control
--page-control-background-hoverrgba(137, 137, 137, .1)rgba(137, 137, 137, .1)Background color on hover
--page-control-closer-hover-background#e1e1e1#444444Background color of the close button on hover
--page-control-border-color#e0e0e0#444444Border color of the page control
--page-control-border-radius6px6pxBorder radius of the page control
/* Custom styling for page control */
.custom-page-control {
--page-control-background: #f5f5f5;
--page-control-background-hover: rgba(0, 123, 255, 0.1);
--page-control-closer-hover-background: #d0d0d0;
--page-control-border-color: #cccccc;
--page-control-border-radius: 8px;
}
  • .page-control - Main container
  • .page-control__tabs - Container for tabs
  • .tabs-position-left - Align tabs to the left
  • .tabs-position-center - Align tabs to the center
  • .tabs-position-right - Align tabs to the right
  • .page-control__tab - Individual tab
  • .page-control__tab.active - Active tab
  • .page-control__tab__icon - Tab icon
  • .page-control__tab__caption - Tab caption/title
  • .page-control__tab__closer - Tab close button
  • .page-control__tab__menu - Tab context menu
  • .page-control__tab__menu__holder - Container for tab menu
  • .page-control__tab__service - Service buttons container
  • .page-control__tab__append - Add tab button
  • .page-control__service-button - Service button
  • .page-control__invisible_tabs_holder - Container for overflow tabs
  1. Tab Management: Create, activate, close, and rename tabs
  2. Overflow Handling: Automatically moves tabs to a dropdown when there’s not enough space
  3. Context Menus: Provides context menus for tabs with various actions
  4. Reference Control: Can control the visibility of referenced elements based on the active tab
  5. Custom Actions: Supports custom actions for tabs and the page control
  6. Tab Icons: Supports icons and images for tabs
  7. Tab Positioning: Supports different tab alignment options
  1. Use clear, concise tab titles to help users navigate content
  2. Consider using icons alongside text for better visual recognition
  3. Use reference control for complex interfaces to show/hide content based on the active tab
  4. Implement appropriate event handlers to respond to tab changes
  5. Consider disabling tab closing for important tabs using the canClose option
  6. Use custom tab actions for frequently used operations
  7. For applications with many tabs, consider grouping related tabs or using a hierarchical structure