Skip to main content

nav-tabs

shadow

Contents

Tabs are a top level navigation component to implement a tab-based navigation. The component is a container of individual Tab components.

The nav-tabs component does not have any styling and works as a router outlet in order to handle navigation. It does not provide any UI feedback or mechanism to switch between tabs. In order to do so, an nav-tab-bar should be provided as a direct child of nav-tabs.

Both nav-tabs and nav-tab-bar can be used as standalone elements. They don’t depend on each other to work, but they are usually used together in order to implement a tab-based navigation that behaves like a native app.

The nav-tab-bar needs a slot defined in order to be projected to the right place in an nav-tabs component.

Interfaces

TabsCustomEvent

While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Navify events emitted from this component.

interface TabsCustomEvent extends CustomEvent {
detail: { tab: string };
target: HTMLNavTabsElement;
}

Usage

<nav-tabs>

<nav-tab tab="tab-schedule">
<nav-nav></nav-nav>
</nav-tab>

<nav-tab tab="tab-speaker">
<nav-nav></nav-nav>
</nav-tab>

<nav-tab tab="tab-map" component="page-map">
<nav-nav></nav-nav>
</nav-tab>

<nav-tab tab="tab-about" component="page-about">
<nav-nav></nav-nav>
</nav-tab>

<nav-tab-bar slot="bottom">
<nav-tab-button tab="tab-schedule">
<nav-icon name="calendar" aria-hidden="true"></nav-icon>
<nav-label>Schedule</nav-label>
<nav-badge>6</nav-badge>
</nav-tab-button>

<nav-tab-button tab="tab-speaker">
<nav-icon name="person-circle" aria-hidden="true"></nav-icon>
<nav-label>Speakers</nav-label>
</nav-tab-button>

<nav-tab-button tab="tab-map">
<nav-icon name="map" aria-hidden="true"></nav-icon>
<nav-label>Map</nav-label>
</nav-tab-button>

<nav-tab-button tab="tab-about">
<nav-icon name="information-circle" aria-hidden="true"></nav-icon>
<nav-label>About</nav-label>
</nav-tab-button>
</nav-tab-bar>

</nav-tabs>

Activating Tabs

Each nav-tab-button will activate one of the tabs when pressed. In order to link the nav-tab-button to the nav-tab container, a matching tab property should be set on each component.

<nav-tab tab="settings">
...
</nav-tab>

<nav-tab-button tab="settings">
...
</nav-tab-button>

The nav-tab-button and nav-tab above are linked by the common tab property.

The tab property identifies each tab, and it has to be unique within the nav-tabs. It's important to always set the tab property on the nav-tab and nav-tab-button, even if one component is not used.

Router integration

When used with Navify's router (nav-router) the tab property of the nav-tab matches the component property of an nav-route.

The following route within the scope of an nav-tabs outlet:

<nav-route url="/settings-page" component="settings"></nav-route>

will match the following tab:

<nav-tab tab="settings" component="settings-component"></nav-tab>

Properties

No properties available for this component.

Events

NameDescription
navTabsDidChangeEmitted when the navigation has finished transitioning to a new component.
navTabsWillChangeEmitted when the navigation is about to transition to a new component.

Methods

getSelected

DescriptionGet the currently selected tab.
SignaturegetSelected() => Promise<string | undefined>

getTab

DescriptionGet a specific tab by the value of its tab property or an element reference.
SignaturegetTab(tab: string | HTMLNavTabElement) => Promise<HTMLNavTabElement | undefined>

select

DescriptionSelect a tab by the value of its tab property or an element reference.
Signatureselect(tab: string | HTMLNavTabElement) => Promise<boolean>

CSS Shadow Parts

No CSS shadow parts available for this component.

CSS Custom Properties

No CSS custom properties available for this component.

Slots

NameDescription
``Content is placed between the named slots if provided without a slot.
bottomContent is placed at the bottom of the screen.
topContent is placed at the top of the screen.
View Source