navigationcontroller
z-switcherSwitcher
Tabbed content switcher with a sliding indicator, keyboard navigation, collapsible and manual modes, and animated panel transitions.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
active | number | — | 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. |
connect | string | '' | 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-connect | boolean | false | Disables panel switching: the tablist still manages active state and keyboard focus, but no panels are shown or hidden. |
manual | boolean | false | Keyboard navigation moves focus without activating tabs; press Enter or Space to show the focused tab. |
collapsible | boolean | false | Allows 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. |
media | string | '' | 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. |
animation | string | '' | 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. |
duration | number | 150 | Panel animation duration in milliseconds; non-finite or negative values fall back to 150. |
no-indicator | boolean | false | Disables 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
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | 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
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
active | z-active | yes | no | Class applied to the active tab item, its trigger, and the active panel; the default cls target for this component. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-switcher:before-change | { index: number; previousIndex: number; item: HTMLElement | null; trigger: HTMLElement | null; value: string | null } | cancelable, bubbles | Fires 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 } | bubbles | Fires after the active tab changes, with the same detail as before-change. |
z-switcher:mount · from Controller | Record<string, unknown> | bubbles | Fires when deferred template content is mounted into the container. |
Methods
| Signature | Description |
|---|---|
index(): number | Returns the index of the active tab, or -1 when all tabs are collapsed. |
refresh(): void | Re-scans the tablist and panels, rebinds listeners, and re-measures the indicator after the DOM changes. |
show(target: number | 'next' | 'previous' | string): boolean | Shows 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
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-fn · from Controller | template | descendant | config | Marks a deferred <template> child whose content is mounted into the container on demand. |
data-open | — | descendant | config | Triggers carrying data-open are skipped during tab detection; the attribute belongs to the dialog toggle system, not the switcher. |
data-switcher-ignore | — | descendant | config | Excludes a tablist child from tab detection; .z-nav-header and .z-nav-divider children are ignored automatically. |
data-switcher-item | next, previous | descendant | trigger | Turns 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 | — | descendant | config | Triggers carrying data-toggle are skipped during tab detection; the attribute belongs to the dialog toggle system, not the switcher. |
data-value | — | descendant | read-only | Identifies 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
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-active | state | .z-switcher | State class marking the active tab item, its trigger, and the active panel. |
.z-switcher | root | z-switcher | Panel container: its direct children are the panels, and every child without .z-active is hidden. |
Keyboard
| Keys | Action | When |
|---|---|---|
| ArrowRight ArrowLeft | Move 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 ArrowUp | Move 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 End | Move 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"andaria-orientation; each trigger getsrole="tab",aria-selected,aria-controls, and a rovingtabindex(0 on the focused tab, -1 on the rest). Disabled triggers getaria-disabled. - Panels get
role="tabpanel"andaria-labelledbypointing at their trigger; inactive panels arehidden. Tab item wrappers that have no role getrole="presentation".