Morphos
Layout

Tabs

A set of layered panels where only one panel is visible at a time, selected via a tab list.

Interactive example

Installation

npm install @morphos/layout
pnpm add @morphos/layout
yarn add @morphos/layout
bun add @morphos/layout

Import

import { Tabs, TabList, Tab, TabPanel } from '@morphos/layout'

Usage

@Component()
class MyComponent extends StatefulComponent {
  @State() tabs = new Tabs({ defaultValue: 'overview' })

  render() {
    return (
      <Tabs tabs={this.tabs}>
        <TabList tabs={this.tabs} aria-label="Product information">
          <Tab tabs={this.tabs} value="overview">Overview</Tab>
          <Tab tabs={this.tabs} value="settings">Settings</Tab>
          <Tab tabs={this.tabs} value="billing">Billing</Tab>
        </TabList>
        <TabPanel tabs={this.tabs} value="overview">
          <p>Overview content.</p>
        </TabPanel>
        <TabPanel tabs={this.tabs} value="settings">
          <p>Settings content.</p>
        </TabPanel>
        <TabPanel tabs={this.tabs} value="billing">
          <p>Billing content.</p>
        </TabPanel>
      </Tabs>
    )
  }
}

Compound components

ComponentDescription
TabsRoot state manager — tracks the selected tab value and the registered tab order
TabListContainer for the tab buttons (role="tablist") — handles arrow-key navigation
TabAn individual tab button (role="tab")
TabPanelThe content panel associated with a tab (role="tabpanel")

Props — Tabs

PropTypeDefaultDescription
valuestringControlled active tab value
defaultValuestringInitial active tab (uncontrolled)
orientation"horizontal" | "vertical""horizontal"Axis of the tab list — determines which arrow keys navigate
onValueChange(value: string) => voidCalled when the active tab changes
classstringCSS class
idstringHTML id

Methods — Tabs

MethodDescription
select(value: string)Selects the given tab value
navigate(direction: "next" | "prev" | "first" | "last")Moves selection to the next/previous/first/last registered tab, wrapping around the ends

Props — TabList

PropTypeDefaultDescription
tabsTabsThe Tabs state instance
aria-labelstringAccessible label for the tab list
aria-labelledbystringID of the element labelling the tab list
childrenChildrenTab elements
classstringCSS class
idstringHTML id

Props — Tab

PropTypeDefaultDescription
tabsTabsThe Tabs state instance
valuestringUnique identifier for this tab
disabledbooleanfalseDisables this tab
childrenChildrenTab label
classstringCSS class
idstringHTML id (defaults to an auto-generated id)

Props — TabPanel

PropTypeDefaultDescription
tabsTabsThe Tabs state instance
valuestringThe tab value this panel belongs to
childrenChildrenPanel content
classstringCSS class
idstringHTML id

Keyboard navigation

TabList handles these keys directly:

KeyAction
ArrowRightMove to the next tab (orientation="horizontal")
ArrowLeftMove to the previous tab (orientation="horizontal")
ArrowDownMove to the next tab (orientation="vertical")
ArrowUpMove to the previous tab (orientation="vertical")
HomeMove to the first tab
EndMove to the last tab

Navigation always selects the target tab immediately (activation follows focus) — there is no separate manual-activation mode.

data-* attributes

AttributeElementWhen present
data-orientationTabsAlways — reflects the orientation prop
data-selectedTab, TabPanelThe tab (or its panel) is the active one
data-disabledTabThe tab's disabled prop is set

Styling example

.morphos-tabs[data-orientation="vertical"] {
  flex-direction: row;
}

.morphos-tabs-tab[data-selected] {
  color: var(--morphos-color-accent);
  border-color: var(--morphos-color-accent);
}

On this page