Header Menu
<mo-header-menu> | MOHeaderMenu
Header menus are used inside the Header to add options for user navigation.
<mo-header-menu label="Menu #2" slot="left-menu"> <mo-menu-item>Dropdown Item 1</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Dropdown Item 2</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Dropdown Item 3</mo-menu-item> </mo-header-menu>
import React, { CSSProperties } from 'react'; import { MOHeaderMenu, MODivider, MOMenuItem} from '@metsooutotec/modes-web-components/dist/react'; export interface dividerCSS extends CSSProperties { '--spacing': number; } const App = () => ( <> <MOHeaderMenu label="Menu" slot="left-menu"> <MOMenuItem>Dropdown Item 1</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Dropdown Item 2</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Dropdown Item 3</MOMenuItem> </MOHeaderMenu> </> );
See the header component for more examples on actual usage.
Examples
With an icon
An icon can be added to the HeaderMenu
by simply using the iconName
property.
<mo-header-menu iconName="settings" label="Menu #2" slot="left-menu"> <mo-menu-item>Dropdown Item 1</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Dropdown Item 2</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Dropdown Item 3</mo-menu-item> </mo-header-menu>
import React, { CSSProperties } from 'react'; import { MOHeaderMenu, MODivider, MOMenuItem} from '@metsooutotec/modes-web-components/dist/react'; export interface dividerCSS extends CSSProperties { '--spacing': number; } const App = () => ( <> <MOHeaderMenu iconName="settings" label="Menu #2" slot="left-menu"> <MOMenuItem>Dropdown Item 1</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Dropdown Item 2</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Dropdown Item 3</MOMenuItem> </MOHeaderMenu> </> );
Only icon + badge
Header menus can be just an icon and also include a badge, to indicate e.g., notifications.
<mo-header-menu noCaret iconName="notification" slot="right-menu"> <mo-badge slot="badge" variant="alert" pill>9</mo-badge> <mo-menu-item><mo-icon slot="prefix" name="notification"></mo-icon>New notifications</mo-menu-item> </mo-header-menu>
Selectable menus
You can create header menus where the mo-menu-item
children are selectable, so that the current
selected one stays highlighted. This can be useful for example if you are using the header menus for routing
between pages to indicate which page is now active.
<mo-header-menu selectable label="Selectable Menu" slot="left-menu"> <mo-menu-item>Selectable Item 1</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Selectable Item 2</mo-menu-item> <mo-divider style="--spacing: 0"></mo-divider> <mo-menu-item>Selectable Item 3</mo-menu-item> </mo-header-menu>
import React, { CSSProperties } from 'react'; import { MOHeaderMenu, MODivider, MOMenuItem} from '@metsooutotec/modes-web-components/dist/react'; export interface dividerCSS extends CSSProperties { '--spacing': number; } const App = () => ( <> <MOHeaderMenu selectable label="Selectable Menu" slot="left-menu"> <MOMenuItem>Selectable Item 1</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Selectable Item 2</MOMenuItem> <MODivider style={ { '--spacing': 0, } as dividerCSS } > </MODivider> <MOMenuItem>Selectable Item 3</MOMenuItem> </MOHeaderMenu> </> );
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component using a bundler:
import '@metsooutotec/modes-web-components/dist/components/header-menu/header-menu.js';
To import this component as a React component:
import MOHeaderMenu from '@metsooutotec/modes-web-components/dist/react/header-menu/';
To import this component using a script tag:
<script type="module" src="https://modes-web.metso.com/dist/components/cdn/components/header-menu/header-menu.js"></script>
Slots
Name | Description |
---|---|
(default) | The default slot. Add mo-menu-item s here. |
badge
|
Badges can be slotted in here, they should position automatically. |
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
dropdown
|
The dropdown element. |
MODropdown
|
- | |
menu
|
The menu element |
MOMenu
|
- | |
label
|
The label in the button. |
string
|
''
|
|
iconName
|
An example property. |
string
|
''
|
|
noCaret
|
Whether the button should include a caret. |
|
boolean
|
false
|
open
|
Whether the dropdown is open. |
|
boolean
|
false
|
selectable
|
Whether the menu items are selectable. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Custom Properties
Name | Description | Default |
---|---|---|
--min-width |
Minimum width of the header menu, 40px by default. |
Learn more about customizing CSS custom properties.
Parts
Name | Description |
---|---|
base |
The component’s internal wrapper. |
button |
The button to open the menu. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.