This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Tabs

A component for toggling between related panels on the same page.

Examples#

Animated panels#

Animate panels as they activate using the data-starting-style and data-ending-style attributes.

The data-activation-direction attribute indicates which direction the newly active tab is relative to the previously active one, letting panels slide in from the correct side.

Hidden until found#

The hiddenUntilFound prop hides the panels that are not selected with hidden="until-found", so the browser can search their contents. A match in a hidden panel selects its tab. It can be set on each TabsPanel, or once on Tabs to apply to all panels.

To try it, press Ctrl+F (Cmd+F on macOS) and search for “deadlines”—the browser selects the tab of the panel that has the match. Older browsers that don’t support hidden="until-found" keep the panels hidden, and find-in-page skips over the contents.

API reference#

Import the components of the family:

use Phem\Ui\Tabs;
use function Phem\Ui\{TabsList, TabsTab, TabsIndicator, TabsPanel};

Tabs#

Tabs and their panels: Base UI Tabs.Root, on the phem-tabs controller.

defaultValue selects a tab on load: the value of a tab. Each tab shows the panel with the same value. With no defaultValue, the first tab that is not disabled is selected. With hiddenUntilFound, a hidden panel has hidden="until-found": the search of the browser finds its text and selects its tab. A tab is not a link: for links to pages, use a <nav> with aria-current="page", or NavigationMenu.

PropTypeDefault
defaultValue?stringnull
orientation'horizontal' | 'vertical'Orientation::Horizontal
activateOnFocusboolfalse
loopFocusbooltrue
hiddenUntilFoundboolfalse
children?Htmlnull
...attrsarray[]

TabsTab#

A tab: a button that selects its panel.

PropTypeDefault
value (required)string—
disabledboolfalse
children?Htmlnull
...restmixed—

TabsPanel#

The content of one tab: it shows when the TabsTab with the same value is active. With hiddenUntilFound, this hidden panel has hidden="until-found", as with the prop of the root.

PropTypeDefault
value (required)string—
hiddenUntilFoundboolfalse
children?Htmlnull
...restmixed—

TabsList#

The row of the TabsTab buttons (tablist), with an optional TabsIndicator.

PropTypeDefault
children?Htmlnull
...restmixed—

TabsIndicator#

A box under the selected tab that moves with the selection (--active-tab-left, --active-tab-width).

PropTypeDefault
...restmixed—

The source of the examples: examples/ui/Tabs.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close