Tabs

On this page

Tabs switch between sections of one page, such as a member's overview, bookings and billing. The kit shows the selected panel, hides the others and handles the keyboard.

Tabs with a count badgeTabs with a count badge

Figure 1: Three tabs, one with a count badge

<div class="ph-tabs" role="tablist" aria-label="Member sections">
  <button type="button" role="tab" id="tab-overview" aria-controls="panel-overview" aria-selected="true">Overview</button>
  <button type="button" role="tab" id="tab-bookings" aria-controls="panel-bookings">Bookings <span class="ph-badge">64</span></button>
  <button type="button" role="tab" id="tab-billing" aria-controls="panel-billing">Billing</button>
</div>
<section id="panel-overview">...</section>
<section id="panel-bookings" hidden>...</section>
<section id="panel-billing" hidden>...</section>

Each tab's aria-controls names its panel. The kit gives the panels role="tabpanel" and links them back to their tabs.

Behaviour

ActionResult
Click a tabSelects it and shows its panel
Left / Right arrowMoves to and selects the previous / next tab
Home / EndSelects the first / last tab
Up / Down arrowMoves between tabs when the tab list has aria-orientation="vertical"

When the selection changes, the tab list fires ph-change with event.detail.value set to the selected panel's id. Switch tabs from code with phApp.tabs.select(tabElement).

document.querySelector('.ph-tabs').addEventListener('ph-change', (event) => {
  if (event.detail.value === 'panel-bookings') loadBookings();
});

React

import { StyledTabs, StyledTab } from 'ph-app-kit-react';

<StyledTabs value={tab} onChange={(_, next) => setTab(next)}>
  <StyledTab value="overview" label="Overview" />
  <StyledTab value="bookings" label="Bookings" />
</StyledTabs>

Guidelines

  • Two to about six tabs, with short labels.
  • Tabs switch sections of one page. To move to another page, use links; to change what a chart shows, use a segmented control.
  • Load a heavy tab's data when it's first selected.