Navbar
<zn-navbar>
ZnNavbar
Navbars show a row of tabs for switching between views, with optional counts, icons and expanding actions.
<zn-navbar navigation="[{"path":"#","title":"Dashboard"},{"path":"#","title":"Another"}]"> </zn-navbar>
Examples
Stacked
Add stacked to list the tabs vertically, such as in the left slot of a
Tabs. Give each navigation item a tab matching the
id of its panel.
<zn-tabs> <zn-navbar slot="left" stacked navigation='[{"tab":"calls","icon":"phone"},{"tab":"home","icon":"home"}]'></zn-navbar> <div id="calls"> <zn-sp>Recent calls</zn-sp> </div> <div id="home"> <zn-sp>Home</zn-sp> </div> </zn-tabs>
Expanding Actions
Put Expanding Actions inside the navbar to show them at the end of the tab row.
Recent labels
<zn-navbar navigation='[{"path":"#","title":"Dashboard"},{"path":"#","title":"Reports"}]'> <zn-expanding-action icon="new_label" method="drop"> <p>Recent labels</p> </zn-expanding-action> </zn-navbar>
Icon Bar
Add icon-bar to draw the tabs as equal-width buttons on a bordered panel.
<zn-navbar icon-bar navigation='[{"path":"#","title":"HTML"},{"path":"#","title":"Text"}]'></zn-navbar>
Pill
Add the pill attribute to draw the tabs as a segmented control: a grey track with a raised pill
that slides to the active tab, stretching and settling with a spring as it moves.
<zn-tabs> <zn-navbar slot="top" pill navigation='[{"tab":"","title":"All"},{"tab":"active","title":"Active"},{"tab":"draft","title":"Draft"},{"tab":"archived","title":"Archived"}]'></zn-navbar> <div id="">All</div> <div id="active">Active</div> <div id="draft">Draft</div> <div id="archived">Archived</div> </zn-tabs>
Counts
Give a navigation item a count selector to show how many elements match it, live, in a badge
after its title. It counts inside the closest zn-settings-container, or else the navbar’s own
document or shadow root, and looks into open shadow roots there. Items a filter has hidden still count, so a
tab can show how many it holds before it is selected. The badge updates as matching elements are added,
removed or change attributes, and hides at zero. Give count as a number instead, such as a
total from the server, to show that number as it is; set navigation again to change it.
A count of 0 is drawn muted. Give an item countColor (error, warning,
success, info or grey) to colour its count while it is above 0, such
as error for a count of things overdue.
Set count-style="inline" to show the count as plain text after the title (Unread · 6) instead of a badge; style either with ::part(count).
Invoice paid
Export finished
New login
<zn-settings-container no-settings> <div slot="filter" attribute="read" default="true">Read</div> <zn-navbar isolated pill navigation='[{"tab":"","title":"All","active":true},{"tab":"read","title":"Unread","count":".demo-item:not([read])"}]'></zn-navbar> <p class="demo-item">Invoice paid</p> <p class="demo-item" read>Export finished</p> <p class="demo-item">New login</p> <zn-button size="small" onclick="this.parentElement.querySelector('.demo-item:not([read])')?.setAttribute('read', '')">Mark one read</zn-button> </zn-settings-container>
Full Width
Add full-width to stretch the tabs so they share the navbar’s width equally.
<zn-navbar full-width navigation='[{"tab":"","title":"All","active":true},{"tab":"open","title":"Open"},{"tab":"closed","title":"Closed"}]'></zn-navbar>
Icon Tabs
Give a navigation item an icon, and optionally an iconColor (any
zn-icon color) and iconSize (pixels, default 20), to lead its title with an icon.
An icon-only item leaves title empty and sets label, shown in a tooltip below the
tab along with its count.
<zn-navbar isolated navigation='[{"tab":"","title":"All","active":true},{"tab":"new","title":"","icon":"inbox@lu","iconColor":"primary","label":"New"},{"tab":"sent","title":"","icon":"send@lu","iconColor":"success","label":"Sent"},{"tab":"overdue","title":"","icon":"triangle-alert@lu","iconColor":"error","label":"Overdue"}]'></zn-navbar>
Compact
Add compact with full-width for a narrow column of icon tabs: each tab has little
padding, and a hovered tab’s icon and count fill as one pill across its cell.
<div style="width: 340px"> <zn-navbar compact full-width isolated show-zero-counts navigation='[{"tab":"","title":"All","active":true,"count":120},{"tab":"new","title":"","icon":"inbox@lu","label":"New","count":17},{"tab":"reply","title":"","icon":"mail@lu","label":"Awaiting reply","count":33},{"tab":"hold","title":"","icon":"clock@lu","label":"On hold","count":0}]'></zn-navbar> </div>
Sliding Indicator
Set --zn-navbar-tab-indicator-slide: 1 to replace each tab’s own line with a single indicator
that slides to the active tab. Style it with ::part(indicator);
--zn-navbar-indicator-top and --zn-navbar-indicator-height give the active tab’s
box, so the indicator can fill the tab as a pill instead of underlining it.
<style> .pill-tabs zn-navbar { --zn-navbar-tab-indicator-slide: 1; --zn-navbar-tab-background: transparent; --zn-navbar-tab-hover-background: transparent; --zn-navbar-tab-hover-backdrop: transparent; --zn-navbar-tab-active-background: transparent; } .pill-tabs zn-navbar::part(container) { border-bottom: 0; } .pill-tabs zn-navbar::part(navbar) { width: fit-content; height: auto; padding: 4px; border-radius: 10px; background: var(--zn-color-neutral-100); } .pill-tabs zn-navbar::part(navbar-item) { z-index: 1; min-height: 32px; border: 0; } .pill-tabs zn-navbar::part(indicator) { z-index: 0; top: var(--zn-navbar-indicator-top); bottom: auto; height: var(--zn-navbar-indicator-height); border-radius: 7px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06); } </style> <zn-tabs class="pill-tabs"> <zn-navbar slot="top" navigation='[{"tab":"","title":"All"},{"tab":"active","title":"Active"},{"tab":"draft","title":"Draft"},{"tab":"archived","title":"Archived"}]'></zn-navbar> <div id="">All</div> <div id="active">Active</div> <div id="draft">Draft</div> <div id="archived">Archived</div> </zn-tabs>
Liquid Indicator
zn-navbar pill draws the tabs as a segmented control with this motion built in. The indicator
moves by its two edges: on a tab change it squishes slightly during
--zn-navbar-tab-indicator-delay, then its leading edge glides to the new tab while the trailing
edge follows on a damped spring, so it stretches a little and settles. Neither edge travels beyond the new
tab. Reduced motion turns all of this off.
<style> .liquid-tabs zn-navbar { /* Squish, then move once the squish is at its deepest */ --zn-navbar-tab-indicator-delay: 60ms; --zn-navbar-tab-indicator-squash: 0.87; /* The leading edge glides in on a drawer curve */ --zn-navbar-tab-indicator-duration: 280ms; --zn-navbar-tab-indicator-easing: cubic-bezier(0.32, 0.72, 0, 1); /* The trailing edge follows on a spring that overshoots once as it catches up */ --zn-navbar-tab-indicator-trail-duration: 400ms; --zn-navbar-tab-indicator-trail-easing: linear(0, 0.044, 0.151, 0.286, 0.428, 0.562, 0.681, 0.78, 0.86, 0.92, 0.964, 0.993, 1.012, 1.023, 1.028, 1.028, 1.026, 1.023, 1.019, 1.015, 1.011, 1.008, 1.005, 1.003, 1.002, 1.001, 1, 1, 1); } </style> <zn-tabs class="pill-tabs liquid-tabs"> <zn-navbar slot="top" navigation='[{"tab":"","title":"All"},{"tab":"active","title":"Active"},{"tab":"draft","title":"Draft"},{"tab":"suspended","title":"Suspended"},{"tab":"archived","title":"Archived"}]'></zn-navbar> <div id="">All</div> <div id="active">Active</div> <div id="draft">Draft</div> <div id="suspended">Suspended</div> <div id="archived">Archived</div> </zn-tabs>
Slots
| Name | Description |
|---|---|
expand
|
Expanding action panels rendered alongside the navbar items. |
bottom
|
Content rendered below the navbar row (e.g. chips, filters). |
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
fullWidth
full-width
|
Stretches the tabs to share the navbar’s full width equally. |
|
boolean
|
- |
compact
|
Tight tabs for a narrow column of icon tabs: little padding around each, and a rounded fill around a
hovered tab’s icon and count that spans its cell. Pair with full-width.
|
|
boolean
|
false
|
pill
|
Draws the tabs as a segmented control: a grey track with a pill that slides to the active tab. |
|
boolean
|
false
|
size
|
With pill, small draws a shorter track to sit with small controls, such as
above a form field.
|
|
'small' | 'medium'
|
'medium'
|
tabs
|
The id of a zn-tabs elsewhere on the page that this navbar’s tabs switch, such as one below a page header. |
|
string
|
- |
countStyle
count-style
|
How item counts show: badge, a pill after the title, or inline, plain text
after a separator (Unread · 6).
|
|
'badge' | 'inline'
|
'badge'
|
showZeroCounts
show-zero-counts
|
Shows a count of 0 rather than hiding the badge when a count selector matches nothing.
|
boolean
|
false
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Custom Properties
| Name | Description | Default |
|---|---|---|
--zn-navbar-tab-body-hover-background |
Fills a hovered tab’s icon, title and count (default transparent). | |
--zn-navbar-tab-indicator-slide |
1 shows the sliding indicator in place of each tab’s own line. |
|
--zn-navbar-tab-indicator-duration |
Duration of the indicator’s leading edge (default 300ms). | |
--zn-navbar-tab-indicator-easing |
Easing of both indicator edges. | |
--zn-navbar-tab-indicator-trail-duration |
Duration of the trailing edge; longer than the lead stretches the indicator. | |
--zn-navbar-tab-indicator-trail-easing |
Easing of the trailing edge; defaults to --zn-navbar-tab-indicator-easing. |
|
--zn-navbar-tab-indicator-trail-delay |
Delay before the trailing edge follows (default 0ms). | |
--zn-navbar-tab-indicator-delay |
Delay before the indicator starts to move (default 0ms). | |
--zn-navbar-tab-indicator-squash |
Vertical scale the indicator squishes to before it travels (default 1, off). |
Parts
| Name | Description |
|---|---|
count |
The count badge of a navigation item with a count. |
navbar-item-body |
A navigation item’s icon, title and count, filled on hover by
--zn-navbar-tab-body-hover-background.
|
indicator |
The active-tab indicator that slides between tabs. Exposes --zn-navbar-indicator-top /
--zn-navbar-indicator-height (the active tab’s box) for styles that fill the tab.
|
Dependencies
This component automatically imports the following dependencies.
<zn-dropdown>