navigationcontrollerz-switcher

Switcher

Tabbed content switcher with a sliding indicator, keyboard navigation, collapsible and manual modes, and animated panel transitions.

Attributes

AttributeTypeDefaultDescription
activenumber—Index of the active tab, kept in sync with the shown panel. Set -1 to collapse all when collapsible is on; an invalid or disabled index falls back to the first enabled tab.
connectstring''CSS selector for external panel containers, matched against the whole document. When empty, panels are taken from .z-switcher containers inside the host or from a following .z-switcher sibling.
no-connectbooleanfalseDisables panel switching: the tablist still manages active state and keyboard focus, but no panels are shown or hidden.
manualbooleanfalseKeyboard navigation moves focus without activating tabs; press Enter or Space to show the focused tab.
collapsiblebooleanfalseAllows the active tab to be closed by clicking it again (or pressing Enter/Space on it), leaving no panel open and active at -1.
orientation'' | 'horizontal' | 'vertical'''Overrides the tablist orientation used for keyboard navigation and aria-orientation. When empty, .z-tab-left, .z-tab-right, and .z-nav (without .z-subnav) infer vertical; everything else is horizontal.
mediastring''Media query that gates a left/right tablist's vertical side layout: while it matches the side class is kept, and when it stops matching the side class is removed.
animationstring''Animation preset applied to a panel as it becomes active. A comma-separated pair uses the first class when moving forward and the second when moving backward.
durationnumber150Panel animation duration in milliseconds; non-finite or negative values fall back to 150.
no-indicatorbooleanfalseDisables the sliding indicator on .z-tab and .z-tab-alt tablists, leaving the active tab's static border or background in place.
Inherited from Base
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''Adds inline styles to named parts as key: styles pairs; a plain string targets the default part.

Custom Styling (cls / stl)

Default cls target:active · defaultstl target:host-inner

KeyDefault classclsstlDescription
activez-activeyesnoClass applied to the active tab item, its trigger, and the active panel; the default cls target for this component.

Events

EventDetailFlagsDescription
z-switcher:before-change{ index: number; previousIndex: number; item: HTMLElement | null; trigger: HTMLElement | null; value: string | null }cancelable, bubblesFires before the active tab changes; preventDefault() cancels the switch. Detail carries the target index, previousIndex, item, trigger, and value.
z-switcher:change{ index: number; previousIndex: number; item: HTMLElement | null; trigger: HTMLElement | null; value: string | null }bubblesFires after the active tab changes, with the same detail as before-change.
z-switcher:mount · from ControllerRecord<string, unknown>bubblesFires when deferred template content is mounted into the container.

Methods

SignatureDescription
index(): numberReturns the index of the active tab, or -1 when all tabs are collapsed.
refresh(): voidRe-scans the tablist and panels, rebinds listeners, and re-measures the indicator after the DOM changes.
show(target: number | 'next' | 'previous' | string): booleanShows a tab by index, by next/previous (wrapping over enabled tabs), or by a value/href string; returns true when the tab is shown. A negative index collapses all when collapsible is on.

Data Hooks

AttributeValuesApplies toRoleDescription
data-fn · from ControllertemplatedescendantconfigMarks a deferred <template> child whose content is mounted into the container on demand.
data-open—descendantconfigTriggers carrying data-open are skipped during tab detection; the attribute belongs to the dialog toggle system, not the switcher.
data-switcher-ignore—descendantconfigExcludes a tablist child from tab detection; .z-nav-header and .z-nav-divider children are ignored automatically.
data-switcher-itemnext, previousdescendanttriggerTurns a descendant element into a remote control: clicking it shows the tab whose index, value, or href matches the attribute, or steps through enabled tabs with next/previous.
data-toggle—descendantconfigTriggers carrying data-toggle are skipped during tab detection; the attribute belongs to the dialog toggle system, not the switcher.
data-value—descendantread-onlyIdentifies a tab for show() and active targeting; read from the trigger or its item, falling back to the trigger href or the tab index.

CSS Classes

ClassRoleApplies toDescription
.z-activestate.z-switcherState class marking the active tab item, its trigger, and the active panel.
.z-switcherrootz-switcherPanel container: its direct children are the panels, and every child without .z-active is hidden.

Keyboard

KeysActionWhen
ArrowRight ArrowLeftMove focus to the next / previous enabled tab, wrapping at the ends; reversed in RTL. Also activates the tab unless manual is set.Focus is on a tab in a horizontal tablist
ArrowDown ArrowUpMove focus to the next / previous enabled tab, wrapping at the ends. Also activates the tab unless manual is set.Focus is on a tab in a vertical tablist
Home EndMove focus to the first / last enabled tab.Focus is on a tab
Enter Show the focused tab, or collapse it when it is already active and collapsible is set.Focus is on a tab

Accessibility

  • The tablist gets role="tablist" and aria-orientation; each trigger gets role="tab", aria-selected, aria-controls, and a roving tabindex (0 on the focused tab, -1 on the rest). Disabled triggers get aria-disabled.
  • Panels get role="tabpanel" and aria-labelledby pointing at their trigger; inactive panels are hidden. Tab item wrappers that have no role get role="presentation".