Tabs

A set of layered sections of content—known as tab panels—that are displayed one at a time.

Features

  • Can be controlled or uncontrolled.
  • Supports horizontal/vertical orientation.
  • Supports automatic/manual activation.
  • Full keyboard navigation.

Install the component from your command line.

npm install @radix-ui/react-tabs

Import the components and piece the parts together.

import * as Tabs from '@radix-ui/react-tabs';
export default () => (
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger />
</Tabs.List>
<Tabs.Content />
</Tabs.Root>
);

Create your styled tabs component from the primitive parts.

Tab one content
import { styled } from 'path-to/stitches.config';
import * as Tabs from '@radix-ui/react-tabs';
const StyledTabs = styled(Tabs.Root, {
display: 'flex',
flexDirection: 'column',
});
const StyledList = styled(Tabs.List, {
flexShrink: 0,
display: 'flex',
borderBottom: '1px solid gainsboro',
});
const StyledTrigger = styled(Tabs.Trigger, {
flexShrink: 0,
padding: '10px 20px',
color: 'slategray',
userSelect: 'none',
'&:hover': { color: 'black' },
'&[data-state="active"]': {
color: 'black',
boxShadow:
'inset 0 -1px 0 0 currentColor, 0 1px 0 0 currentColor',
},
});
const StyledContent = styled(Tabs.Content, {
flexGrow: 1,
padding: 20,
});
export default () => (
<StyledTabs defaultValue="tab1">
<StyledList aria-label="tabs example">
<StyledTrigger value="tab1">One</StyledTrigger>
<StyledTrigger value="tab2">Two</StyledTrigger>
<StyledTrigger value="tab3">Three</StyledTrigger>
</StyledList>
<StyledContent value="tab1">Tab one content</StyledContent>
<StyledContent value="tab2">Tab two content</StyledContent>
<StyledContent value="tab3">Tab three content</StyledContent>
</StyledTabs>
);

Contains all the tabs component parts.

PropTypeDefault
asenumdiv
defaultValuestringNo default value
valuestringNo default value
onValueChangefunctionNo default value
orientationenum"horizontal"
direnum"ltr"
activationModeenum"automatic"

Contains the triggers that are aligned along the edge of the active content.

PropTypeDefault
asenumdiv
loopbooleantrue

The button that activates its associated content.

PropTypeDefault
asenumdiv
value*stringNo default value
disabledbooleanfalse

Contains the content associated with each trigger.

PropTypeDefault
asenumdiv
value*stringNo default value

You can create vertical tabs by using the orientation prop.

Tab one content
import { styled } from 'path-to/stitches.config';
import * as Tabs from '@radix-ui/react-tabs';
const StyledTabs = styled(Tabs.Root, {
display: 'flex',
});
const StyledList = styled(Tabs.List, {
flexShrink: 0,
flexDirection: 'column',
display: 'flex',
borderRight: '1px solid gainsboro',
});
const StyledTrigger = styled(Tabs.Trigger, {
flexShrink: 0,
padding: '10px 20px',
color: 'slategray',
userSelect: 'none',
'&:hover': { color: 'black' },
'&[data-state="active"]': {
color: 'black',
boxShadow: 'inset -1px 0 0 currentColor, 1px 0 0 currentColor',
},
});
const StyledContent = styled(Tabs.Content, {
flexGrow: 1,
padding: 20,
});
export default () => (
<StyledTabs defaultValue="tab1" orientation="vertical">
<StyledList aria-label="tabs example">
<StyledTrigger value="tab1">One</StyledTrigger>
<StyledTrigger value="tab2">Two</StyledTrigger>
<StyledTrigger value="tab3">Three</StyledTrigger>
</StyledList>
<StyledContent value="tab1">Tab one content</StyledContent>
<StyledContent value="tab2">Tab two content</StyledContent>
<StyledContent value="tab3">Tab three content</StyledContent>
</StyledTabs>
);

Adheres to the Tabs WAI-ARIA design pattern.

KeyDescription
TabWhen focus moves onto the tabs, focuses the active trigger. When a trigger is focused, moves focus to the active content.
ArrowDownMoves focus to the next trigger depending on orientation and activates its associated content.
ArrowRightMoves focus to the next trigger depending on orientation and activates its associated content.
ArrowUpMoves focus to the previous trigger depending on orientation and activates its associated content.
ArrowLeftMoves focus to the previous trigger depending on orientation and activates its associated content.
HomeMoves focus to the first trigger and activates its associated content.
EndMoves focus to the last trigger and activates its associated content.