Tabs
Tabs
component allows you to switch between different content.Basic usage
Tabs
components should wrap Tabs.Tab
components that will define the value
(identifier),
label
, and content of each tab.tsxCopied1<Tabs defaultValue="overview">2<Tabs.Tab value="overview" label="Overview">3Overview content here4</Tabs.Tab>5<Tabs.Tab value="team" label="Team Detail">6Team detail content here7</Tabs.Tab>8<Tabs.Tab value="user" label="User Detail">9User detail content here10</Tabs.Tab>11</Tabs>
Placement
placement
prop indicates where the tabs should be relative to the content. By default, the
tabs will be oriented horizontally and placed above the content. You can set placement
to bottom
to have horizontal tabs below the content. For vertical tabs, you can set placement
to left
or
right
.tsxCopied1<Title order={4}>Tabs placement: bottom</Title>2<Tabs defaultValue="overview" placement="bottom">3{tabs}4</Tabs>5<Title order={4}>Tabs placement: left</Title>6<Tabs defaultValue="overview" placement="left">7{tabs}8</Tabs>9<Title order={4}>Tabs placement: right</Title>10<Tabs defaultValue="overview" placement="right">11{tabs}12</Tabs>
Position
position
prop will define where the tabs are positioned along the main axis. By default, the
tabs be at the start
of the main axis. You can also set position
to center
, end
, or apart
.tsxCopied1<Title order={4}>Tabs position: center</Title>2<Tabs defaultValue="overview" position="center">3{tabs}4</Tabs>5<Title order={4}>Tabs position: end</Title>6<Tabs defaultValue="overview" position="end">7{tabs}8</Tabs>9<Title order={4}>Tabs position: apart</Title>10<Tabs defaultValue="overview" position="apart">11{tabs}12</Tabs>
Color
color
prop on the Tab
component
or for individual tabs using the color
prop on each Tabs.Tab
component. If both are set, the
color
on the Tabs.Tab
component will take precedence.tsxCopied1<Tabs defaultValue="overview" color="cyan">2<Tabs.Tab value="overview" label="Overview" />3<Tabs.Tab value="team" label="Team Detail" />4<Tabs.Tab value="user" label="User Detail" />5</Tabs>6<Tabs defaultValue="overview" color="cyan">7<Tabs.Tab value="overview" label="Overview" color="orange" />8<Tabs.Tab value="team" label="Team Detail" />9<Tabs.Tab value="user" label="User Detail" color="green" />10</Tabs>
Disabling
Tabs.Tab
components using the disabled
prop.tsxCopied1<Tabs defaultValue="overview">2<Tabs.Tab value="overview" label="Overview">3Overview content here4</Tabs.Tab>5<Tabs.Tab value="team" label="Team Detail" disabled>6Team detail content here7</Tabs.Tab>8<Tabs.Tab value="user" label="User Detail">9User detail content here10</Tabs.Tab>11</Tabs>
Routing-aware tabs
routingKey
prop. This is useful when
you want to be able to share a link to a specific tab.routingKey
specifies the URL query parameter that will be used to store the active tab. The
routingKey
will be used as the parameter name and the value
of the active Tabs.Tab
will be
used as the parameter value.routingKey
to activeTab
.tsxCopied1<Tabs routingKey="activeTab">2<Tabs.Tab value="overview" label="Overview">3Overview content here4</Tabs.Tab>5<Tabs.Tab value="team" label="Team Detail">6Team detail content here7</Tabs.Tab>8<Tabs.Tab value="user" label="User Detail">9User detail content here10</Tabs.Tab>11</Tabs>
https://app.airplane.dev/views/vew123?activeTab=team
. You can share this URL with others to link
them directly to the "Team Detail" tab.Fixed height vertical tabs
Tabs
, set a height
on the parent container of the Tabs
. The content will scroll if it overflows the height.tsxCopied1<div style={{ height: 200 }}>2<Tabs defaultValue="overview" placement="left">3<Tabs.Tab value="overview" label="Overview">4{loremParagraphs.slice(0, 5).map((p) => (5<Text key={p}>{p}</Text>6))}7</Tabs.Tab>8<Tabs.Tab value="team" label="Team Detail">9{loremParagraphs.map((p) => (10<Text key={p}>{p}</Text>11))}12</Tabs.Tab>13<Tabs.Tab value="user" label="User Detail">14{loremParagraphs.slice(0, 2).map((p) => (15<Text key={p}>{p}</Text>16))}17</Tabs.Tab>18</Tabs>19</div>
Unmounting
keepMounted={false}
. This is useful when the tab content includes
components that impact performance, e.g. calling slow tasks. Note that components that are rendered
inside Tabs.Panel will reset their state on each mount (tab change).tsxCopied1<Tabs defaultValue="overview" keepMounted={false}>2<Tabs.Tab value="overview" label="Overview">3<Checkbox label="Overview" />4</Tabs.Tab>5<Tabs.Tab value="team" label="Team Detail">6<Checkbox label="Team detail" />7</Tabs.Tab>8<Tabs.Tab value="user" label="User Detail">9<Checkbox label="User detail" />10</Tabs.Tab>11</Tabs>
Component API
Tabs
Tab content. Expecting Tabs.Tab components.
Accent color of the active tab.
The tabs value on initial render.
If true, the tabs will save the active tab in the URL.
Whether tabs should take the whole space. If true, the element will grow to fill available space.
This prop works only if the element is a direct child of a Stack.
The ID referenced by the global component state.
If false, content of the tabs will not stay mounted when tab is inactive.
Callback when the value of the active tab changes when using as a controlled component. Prefer using the global component state.
How list of tabs is placed relative to the content. If top or bottom, tabs will be oriented horizontally. If left or right, tabs will be oriented vertically.
How tabs are positioned along the main axis.
URL param key for saving the active tab in the URL.
Set to null to disable routing for this Tabs component.
Value of the active tab if using this component as a controlled component. Prefer to use the component state to get the value.
Tabs.Tab
Content of the tab panel.
Accent color of the tab. Will override the color from the Tabs parent component if set.
If true, tab is disabled.
Adds an icon to the left of the tab label.
Content of the label for the tab. Can be a string or a React component.
Identifier for the tab. Used by Tabs parent component when determining the active tab.
State API
Sets the active Tabs.Tab.
The identifier of the currently active Tabs.Tab component.