Navigation

Tabs

Horizontal tabs that show one panel at a time, with manual activation and arrow-key navigation.

Class nameTypeDescription
tabsplf:tabsComponentThe tab list
tabplf:tabPartA tab
tab-contentplf:tab-contentPartA tab's panel
tabs-boxplf:tabs-boxStyleTabs in a muted box
tabs-liftplf:tabs-liftStyleThe selected tab joins a bordered panel
tabs-borderplf:tabs-borderStyleA line under the list, thicker under the selected tab
Content for tab one.
Content for tab two.
Content for tab three.

The tabs show the panels in order. Tabs are horizontal only: a tab list with aria-orientation="vertical" does not start.

Content for tab one.
Content for tab two.
Content for tab three.
Content for tab one.
Content for tab two.
Content for tab three.

Disabled

At least one tab must stay enabled.

Content for the active tab.
Content for the enabled tab.
Content for the disabled tab.

Selected from code

The script opens the Billing tab from a button outside the tabs, with select() and the panel’s id.

Your card expires this month

Update it to keep your plan active.

Name, email and avatar.
Payment method and invoices.

JavaScript

Tabs needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-tabs Marks the container
aria-controls On a tab, its panel’s id; leave it off every tab to show the panels in order
aria-selected="true" The tab selected at first; otherwise the first enabled tab
disabled, aria-disabled="true" A tab that cannot be selected

The script sets aria-selected, the tabs’ tabindex, hidden on inactive panels and each panel’s aria-labelledby; it adds the ids and aria-controls the markup leaves out, and tabindex="0" on a panel without a focusable element.

Methods

Method Behavior
PLF.Tabs.getOrCreateInstance(element) Returns the instance, creating it for valid markup
PLF.Tabs.getInstance(element) Returns the instance or null
instance.select(panelId) Selects the tab of the panel with this id, which you write on a panel you select from code. Returns false when canceled or when the tab is disabled, selected or unknown
instance.destroy() Removes listeners and shows every panel again
Event When
plf:tabs:before-change Before a tab is selected; cancelable
plf:tabs:change After a tab is selected

Each event’s detail:

Property Value
instance The Tabs instance
reason api, trigger or keyboard
trigger The tab that selected the panel, or null from a method
previousPanelId The id of the panel shown before the change
panelId The id of the panel the change selects
Key Action
Left Arrow, Right Arrow Move focus to the previous or next enabled tab, wrapping; reversed right to left
Home, End Move focus to the first or last enabled tab
Enter, Space Selects the focused tab
Tab Leaves the tab list for the visible panel

React

Tabs from @pelatform/react renders these tabs and their panels, with the runtime’s keyboard: it keeps its own state, or the application sets it with value, and each part is a component of its own.

Prop Values Default
value The selected tab’s value, which the application changes in onValueChange Its own state
defaultValue The value of the tab selected at first, when the application does not set value Required without value
onValueChange (value), called when a click, Enter or Space selects another tab; keep value to stay on the tab None
Part Element
TabsList A div with tabs, the tab list; variant is box, lift or border
Tab A button with tab, type="button", whose value, unique in its Tabs, pairs it with its panel
TabContent A div with tab-content, the panel of the Tab with the same value; tabindex="0" brings Tab to it, and a panel that starts with a control can take tabIndex={-1}

The other props are the element’s own, className and ref included; Tabs writes the ids that pair each tab with its panel.

Variable Default
--plf-tabs-list-bg Muted surface
--plf-tabs-height 36px
--plf-tabs-padding-inline 12px
--plf-tabs-radius Medium radius (6px)
--plf-tabs-selected-bg Field color; the surface on tabs-lift; none on tabs-border
--plf-tabs-selected-color Text, and the selected tab’s line on tabs-border
--plf-tabs-lift-border Subtle border, around the selected tab and panel of tabs-lift
--plf-tabs-border-color Subtle border, the line under the list of tabs-border

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons