Tabs
Tabs can be a helpful way of letting users quickly switch between related information. From tablet width up they are tabs; below it, and without JavaScript, they are a list of links to every panel.
Read the Design System guidance for tabs
Import
import * as Tabs from 'govuk-react/tabs';Examples
Default
Code
<Tabs.Composite items={items} />Radios
Code
<Tabs.RadiosComposite items={items} name="cases-radios" />With parts
Code
<Tabs.Root defaultValue="parts-past-week">
<Tabs.Title />
<Tabs.List>
{items.map((item) => (
<Tabs.ListItem key={item.id} value={`parts-${item.id}`}>
<Tabs.Tab value={`parts-${item.id}`}>{item.label}</Tabs.Tab>
</Tabs.ListItem>
))}
</Tabs.List>
{items.map((item) => (
<Tabs.Panel key={item.id} value={`parts-${item.id}`}>
{item.panel}
</Tabs.Panel>
))}
</Tabs.Root>Controlled
Code
<ControlledTabs />API reference
Tabs.Root
Tabs can be a helpful way of letting users quickly switch between related information.
As in govuk-frontend, without JavaScript the tabs are a list of links to every panel. Use Tab
and Panel inside it. Each tab's value is its panel's id.
| Prop | Type |
|---|---|
onValueChangeCalled when the user selects a tab. | (value: string, details: ChangeDetails) => void |
nameThe panels' radio group name. Defaults to a generated one. | string |
valueThe selected tab's value, to control the tabs. | string |
defaultValueThe tab selected at first, when uncontrolled. Defaults to the first tab. | string |
Tabs.RadiosRoot
Tabs that switch panels without JavaScript too, through a hidden radio in each panel. Use
RadioTab and RadioPanel inside it. Each tab's value is its panel's id.
| Prop | Type |
|---|---|
onValueChangeCalled when the user selects a tab. | (value: string, details: ChangeDetails) => void |
nameThe panels' radio group name. Defaults to a generated one. | string |
value | string |
defaultValue | string |
Tabs.Composite
The tabs, with a tab and panel for each item. Without JavaScript, a list of links to every panel.
| Prop | Type |
|---|---|
defaultValueThe tab selected at first, when uncontrolled. Defaults to the first tab. | string |
onValueChangeCalled when the user selects a tab. | (value: string, details: ChangeDetails) => void |
nameThe panels' radio group name. Defaults to a generated one. | string |
valueThe selected tab's value, to control the tabs. | string |
titleThe heading shown above the list of links when the tabs aren't shown. Defaults to "Contents". | ReactNode |
itemsRequired | CompositeItem[] |
Tabs.List
No props of its own. Other props are passed to the element it renders.
Tabs.ListItem
| Prop | Type |
|---|---|
selected | boolean |
Tabs.Panel
A panel in a Root.
| Prop | Type |
|---|---|
selected | boolean |
valueRequiredIts tab's value, which is the panel's id. | string |
nameThe panels' radio group name. Set by Root: pass it to a panel rendered without one, such as in an island. | string |
Tabs.RadioPanel
A panel in a RadiosRoot, shown without JavaScript only while its tab is chosen.
| Prop | Type |
|---|---|
selected | boolean |
valueRequiredIts tab's value, which is the panel's id. | string |
nameThe panels' radio group name. Set by Root: pass it to a panel rendered without one, such as in an island. | string |
Tabs.RadiosComposite
The tabs, with a tab and panel for each item. They switch panels without JavaScript too.
| Prop | Type |
|---|---|
onValueChangeCalled when the user selects a tab. | (value: string, details: ChangeDetails) => void |
nameThe panels' radio group name. Defaults to a generated one. | string |
titleThe heading shown above the list of tabs when they aren't styled as tabs. Defaults to "Contents". | ReactNode |
itemsRequired | CompositeItem[] |
valueThe selected tab's value, to control the tabs. | string |
defaultValueThe tab selected at first, when uncontrolled. Defaults to the first tab. | string |
Tabs.RadioTab
A tab in a RadiosRoot: a label for its panel's radio.
| Prop | Type |
|---|---|
valueRequiredIts panel's value, which is the panel's id. | string |
nameThe panels' radio group name. Set by RadiosRoot: pass it to a tab rendered without one, such as in an island. | string |
Tabs.Tab
A tab in a Root: a link to its panel.
| Prop | Type |
|---|---|
valueRequiredIts panel's value, which is the panel's id. | string |
Tabs.Title
No props of its own. Other props are passed to the element it renders.