Tabs

Material Design 3 tabs web components (lit-material-tabs, lit-material-tab).

  • 3.4 KB gzipped
  • @lit-material/tabs 0.2.0
  • Renders on the server

Example

Install

npm install @lit-material/tabs @lit-material/tokens
import "@lit-material/tabs";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-tab-panel>

Content for one tab. Place lit-material-tab-panel elements as siblings after a lit-material-tabs (same parent): the tabs pair them with their tabs by index, show the selected one, and wire aria-labelledby / aria-controls between them.

Properties

PropertyAttributeTypeDefaultDescription
selectedselectedbooleanfalseWhether this panel is shown. Managed by the preceding lit-material-tabs.

Slots

SlotDescription
defaultThe panel's content.

<lit-material-tab>

A single tab within lit-material-tabs. Purely presentational — it has no click handler of its own; the parent listens for the bubbling click (via event.composedPath(), the same delegation pattern lit-material-select and lit-material-menu use) and drives selected/roving tabindex from there, the same way lit-material-select-option's selected is entirely managed by its parent.

Properties

PropertyAttributeTypeDefaultDescription
selectedselectedbooleanfalse
disableddisabledbooleanfalse
ariaControlsaria-controlsstring | nullnullId of the panel this tab shows. The button lives in this element's shadow root, where an id can't reach the page, so the panel is linked through ARIA element reflection (ariaControlsElements) where the browser has it.

Slots

SlotDescription
defaultThe tab's label.
iconAn optional icon shown above the label.

CSS parts

PartDescription
tabThe button (background/padding).
rippleThe state-layer element the hover/press feedback is drawn on.
focus-ringThe focus indicator element.

<lit-material-tabs>

Material Design 3 tabs — a horizontal row of lit-material-tab elements with a sliding active indicator, following the WAI-ARIA tabs pattern with automatic activation (moving focus with the arrow keys immediately switches the selected tab, matching real Material Design tab behavior — the same roving-tabindex, wrap-on-arrow-keys, activate-immediately model lit-material-radio already uses for its group).

Properties

PropertyAttributeTypeDefaultDescription
selectedselectednumber0Index of the selected tab.

Events

EventDescription
changeFires when the selected tab changes via user interaction.

Slots

SlotDescription
defaultlit-material-tab elements.

CSS parts

PartDescription
tablistThe container (the tabs' row plus the divider beneath it).
indicatorThe sliding active-tab indicator.

Source on GitHub npm