Tabs
Switches between views of the same area, with the ARIA tabs pattern handled. The caller holds the selection. Imported from `murray/universal/tabs`.
compliant
- Overview
- Props
Tabs is imported from murray/universal/tabs, not from the murray barrel:
import { Tabs } from "murray/universal/tabs";
The caller holds the selection: pass the selected tab and apply onTabChange, whether the value lives in a useState or in the URL. A tab's controls matches a Tabs.Content panelId and defaults to the tab's own tab value. The component wires the tablist, tab and tabpanel roles, aria-selected, aria-controls and the roving focus (arrow keys, Home, End) for you. Inactive panels preserve their content and local state using React's Activity.
Hidden panels can render in the background. React cleans up their effects while hidden and recreates them when the panel becomes visible. Changing props can still trigger re-renders.
Declare Tabs.Tab directly inside Tabs.List. Arrays, conditionals and fragments work; custom components wrapping Tabs.Tab do not. Each tab needs a unique tab value. The list uses the shared TabList renderer and scrolls horizontally when tabs overflow.
Health panel
Shared panel
Give several tabs the same controls value to let them control one panel. The content stays mounted when switching between those tabs, preserving its local state. Use the controlled tab value to update what it displays.
<Tabs tab={tab} onTabChange={setTab}>
<Tabs.List aria-label="Claim status">
<Tabs.Tab tab="all" controls="claims">
All
</Tabs.Tab>
<Tabs.Tab tab="pending" controls="claims">
Pending
</Tabs.Tab>
</Tabs.List>
<Tabs.Content panelId="claims">
<ClaimsList status={tab} />
</Tabs.Content>
</Tabs>
Each controlling tab's aria-controls points to the same panel. The panel's accessible name follows the selected tab. Switching to a tab that controls another panel hides the shared panel and preserves its state for when the user returns.
Accessible name
Tabs.List requires an aria-label: it is what a screen reader announces when entering the tab set. Use a localized string.
Keyboard
Arrow keys only move the focus between tabs; Enter, Space or a click selects one. The visible panel does not switch while a keyboard user browses the tabs.
Secondary variant
The secondary variant renders pills instead of an underline.
All panel
Disabled tab
A disabled tab stays visible and announced, but cannot be selected or focused.
Health panel
murray and murray/mobile.Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| onTabChange | any | |||
| sx | any | |||
| tab | any | |||
| variant | any |