NavigationBar
The navigation bar facilitates easy switching between main pages on mobile devices.
Usage
Import the component:
import 'mdui/components/navigation-bar.js';
import 'mdui/components/navigation-bar-item.js';
Import the TypeScript type:
import type { NavigationBar } from 'mdui/components/navigation-bar.js';
import type { NavigationBarItem } from 'mdui/components/navigation-bar-item.js';
Example: (Note: The style="position: relative" in the example is for demonstration purposes. Remove it in actual use.)
<mdui-navigation-bar value="item-1" style="position: relative">
<mdui-navigation-bar-item icon="place" value="item-1">Item 1</mdui-navigation-bar-item>
<mdui-navigation-bar-item icon="commute" value="item-2">Item 2</mdui-navigation-bar-item>
<mdui-navigation-bar-item icon="people" value="item-3">Item 3</mdui-navigation-bar-item>
</mdui-navigation-bar>Note:
By default, this component uses a position: fixed style and automatically adds a padding-bottom style to the body to prevent page content from being obscured. However, it uses a position: absolute style in the following cases:
- When the
scroll-targetattribute is specified. In this case,padding-bottomis added to the specified element. - When it's inside the
<mdui-layout></mdui-layout>component. In this case,padding-bottomis not added.
Examples
Label Visibility
Text labels in the navigation bar are always visible when there are 3 or fewer navigation items. If there are more than 3 items, only the text of the selected item is displayed.
The label-visibility attribute on <mdui-navigation-bar> controls the visibility of text labels. Possible values:
selected: Only the text of the selected item is displayed.labeled: Text is always displayed.unlabeled: Text is never displayed.
In Container
By default, the navigation bar is relative to the current window and appears at the bottom of the page.
If you want to place the navigation bar within a specific container, use the scroll-target attribute on <mdui-navigation-bar>. The value should be the CSS selector or DOM element of the container with scrollable content. In this case, the navigation bar will be relative to the parent element. You need to manually add the styles position: relative; overflow: hidden to the parent element.
Hide on Scroll
The scroll-behavior attribute on <mdui-navigation-bar> controls the visibility of the navigation bar during scrolling. Set its value to hide to hide the navigation bar when scrolling down and show it when scrolling up.
The scroll-threshold attribute sets the number of pixels to start hiding the navigation bar.
Icons
The icon attribute on <mdui-navigation-bar-item> sets the icon for the inactive state. The active-icon attribute sets the icon for the active state. Alternatively, use the icon and active-icon slots to set the icons for the inactive and active states.
Link
Use the href attribute on the <mdui-navigation-bar-item> component to turn the navigation item into a link. The download, target, and rel attributes are available for link-related functionality.
Badge
You can add a badge to the <mdui-navigation-bar-item> component using the badge slot.
mdui-navigation-bar-item API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
icon | icon | string | - | |
Specifies the Material Icons name for the inactive state. Alternatively, use | ||||
active-icon | activeIcon | string | - | |
Specifies the Material Icons name for the active state. Alternatively, use | ||||
value | value | string | - | |
The value of the navigation item. | ||||
href | href | string | - | |
The URL for the hyperlink. If specified, the component renders as an | ||||
download | download | string | - | |
Instructs the browser to treat the linked URL as a download. Note: This is only available when | ||||
target | target | '_blank' | '_parent' | '_self' | '_top' | - | |
Defines where to display the linked URL. Possible values:
Note: This is only available when | ||||
rel | rel | 'alternate' | 'author' | 'bookmark' | 'external' | 'help' | 'license' | 'me' | 'next' | 'nofollow' | 'noreferrer' | 'opener' | 'prev' | 'search' | 'tag' | - | |
Specifies the relationship of the linked URL as space-separated link types. Possible values:
Note: This is only available when | ||||
autofocus | autofocus | boolean | false | |
Determines if the element should be focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
Specifies the order in which the element receives focus when navigating with the Tab key. | ||||
Methods
| Name | Parameters | Returns |
|---|---|---|
click | void | |
Simulates a mouse click on the element. | ||
focus |
| void |
Sets focus on the element. An optional parameter can be an object with a | ||
blur | void | |
Removes focus from the element. | ||
Slots
| Name |
|---|
| (default) |
Text. |
icon |
Icon. |
active-icon |
Icon for the active state. |
badge |
Badge. |
CSS Custom Properties
| Name |
|---|
--shape-corner-indicator |
The size of the component corner. You can use a specific pixel value, but it's recommended to reference design tokens. |
mdui-navigation-bar API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
hide | hide | boolean | false | |
Hides the navigation bar when set. | ||||
label-visibility | labelVisibility | 'auto' | 'selected' | 'labeled' | 'unlabeled' | 'auto' | |
Specifies the visibility of the text. Possible values:
| ||||
value | value | string | - | |
The value of the selected | ||||
scroll-behavior | scrollBehavior | 'hide' | 'shrink' | 'elevate' | - | |
Defines the scroll behavior. Possible values:
| ||||
scroll-target | scrollTarget | string | HTMLElement | JQ<HTMLElement> | - | |
The element that listens for scroll events. Accepts a CSS selector, DOM element, or JQ object. Defaults to | ||||
scroll-threshold | scrollThreshold | number | - | |
The scroll distance (in pixels) that triggers the scroll behavior. | ||||
order | order | number | - | |
Specifies the layout order within the | ||||
Events
| Name |
|---|
change |
Emitted when the value changes. |
show |
Emitted when the navigation bar starts to show. Can be prevented with |
shown |
Emitted after the navigation bar has shown and animations are complete. |
hide |
Emitted when the navigation bar starts to hide. Can be prevented with |
Emitted after the navigation bar has hidden and animations are complete. |
CSS Custom Properties
| Name |
|---|
--shape-corner |
The size of the component corner. You can use a specific pixel value, but it's recommended to reference design tokens. |
--z-index |
The CSS |