NavigationBar
The navigation bar makes it easy to switch 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. Don't include it in production.)
<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
With three or fewer items, labels in the navigation bar are always visible. When there are more than three items, only the selected item's label is shown.
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 fixed to the bottom of the viewport.
To place the navigation bar in a specific container, set the scroll-target attribute on <mdui-navigation-bar> to the CSS selector or DOM element for the scrollable container. In this case, the navigation bar is positioned relative to its parent element. You must add the styles position: relative; overflow: hidden to the parent element yourself.
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.
Use the scroll-threshold attribute to set how many pixels must be scrolled before the navigation bar starts hiding.
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 link. When set, the component renders as an | ||||
download | download | string | - | |
Downloads the linked URL. Note: Only available when | ||||
target | target | '_blank' | '_parent' | '_self' | '_top' | - | |
Controls where the linked URL opens. Possible values:
Note: 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: Only available when | ||||
autofocus | autofocus | boolean | false | |
Whether the element is focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
The element's tab order 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 object parameter may include 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 corner radius of the indicator. You can use a specific pixel value, but it is recommended to reference design tokens. |
mdui-navigation-bar API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
hide | hide | boolean | false | |
Whether the navigation bar is hidden. | ||||
label-visibility | labelVisibility | 'auto' | 'selected' | 'labeled' | 'unlabeled' | 'auto' | |
Specifies when the text is shown. 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 to watch for scroll events. Accepts a CSS selector, a DOM element, or a JQ object. Defaults to | ||||
scroll-threshold | scrollThreshold | number | - | |
The scroll distance (in pixels) required to trigger 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 corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens. |
--z-index |
The CSS |