Skip to main content

Tabs

Tabbed content panels using the <primus-tabs> web component from @primus/ui-core. Handles keyboard navigation, ARIA attributes, and panel switching automatically.

Requires JS bundle

<primus-tabs> is a Web Component โ€” requires @primus/ui-core JS bundle loaded in your app.

Preview ยท Tabs

Codeโ€‹

<!-- Pill style (default) -->
<primus-tabs>
<div role="tablist">
<button role="tab">Overview</button>
<button role="tab">Transactions</button>
<button role="tab">Settings</button>
</div>
<div role="tabpanel">
<p>Overview content here.</p>
</div>
<div role="tabpanel">
<p>Transaction list here.</p>
</div>
<div role="tabpanel">
<p>Settings form here.</p>
</div>
</primus-tabs>

<!-- Underline style -->
<primus-tabs>
<div role="tablist" class="underline">
<button role="tab">General</button>
<button role="tab">Security</button>
<button role="tab">Notifications</button>
</div>
<div role="tabpanel">General settings</div>
<div role="tabpanel">Security settings</div>
<div role="tabpanel">Notification preferences</div>
</primus-tabs>

<!-- Listen for tab change event -->
<script>
document.querySelector('primus-tabs')
.addEventListener('primus-tab-change', (e) => {
const { index, tab } = e.detail;
console.log(`Switched to tab ${index}: ${tab.textContent}`);
});
</script>

API Referenceโ€‹

Structureโ€‹

ElementRoleDescription
<primus-tabs>ContainerWeb Component โ€” manages state and ARIA
<div role="tablist">Tab barWrapper for tab buttons
<button role="tab">Tab buttonClickable tab โ€” active one gets aria-selected="true"
<div role="tabpanel">PanelContent panel โ€” shown/hidden by the component

Stylesโ€‹

Class on tablistAppearance
(none)Pill style โ€” active tab has card background
underlineUnderline style โ€” active tab has coloured bottom border

Eventsโ€‹

Eventevent.detailDescription
primus-tab-change{ index: number, tab: HTMLElement }Fired when active tab changes

Keyboard navigationโ€‹

KeyAction
โ† / โ†’Move between tabs
HomeGo to first tab
EndGo to last tab
Enter / SpaceActivate focused tab
Version history

See the Changelog for version history and breaking changes.