Tabs
Tabs organize content into multiple sections and allow users to navigate between them. The content under the set of tabs should be related and form a coherent unit.
| install | yarn add @react-spectrum/tabs |
|---|---|
| version | 3.0.0-beta.0 |
| usage | import {Tabs, Item} from '@react-spectrum/tabs' |
Example#
import {Content} from '@react-spectrum/view';
import {Text} from '@react-spectrum/text';
<Tabs aria-label="History of Ancient Rome">
<TabList>
<Item key="FoR">Founding of Rome</Item>
<Item key="MaR">Monarchy and Republic</Item>
<Item key="Emp">Empire</Item>
</TabList>
<TabPanels>
<Item key="FoR">
<Text>Arma virumque cano, Troiae qui primus ab oris.</Text>
</Item>
<Item key="MaR">
<Text>Senatus Populusque Romanus.</Text>
</Item>
<Item key="Emp">
<Text>Alea jacta est.</Text>
</Item>
</TabPanels>
</Tabs>import {Content} from '@react-spectrum/view';
import {Text} from '@react-spectrum/text';
<Tabs aria-label="History of Ancient Rome">
<TabList>
<Item key="FoR">Founding of Rome</Item>
<Item key="MaR">Monarchy and Republic</Item>
<Item key="Emp">Empire</Item>
</TabList>
<TabPanels>
<Item key="FoR">
<Text>
Arma virumque cano, Troiae qui primus ab oris.
</Text>
</Item>
<Item key="MaR">
<Text>Senatus Populusque Romanus.</Text>
</Item>
<Item key="Emp">
<Text>Alea jacta est.</Text>
</Item>
</TabPanels>
</Tabs>import {Content} from '@react-spectrum/view';
import {Text} from '@react-spectrum/text';
<Tabs aria-label="History of Ancient Rome">
<TabList>
<Item key="FoR">
Founding of Rome
</Item>
<Item key="MaR">
Monarchy and
Republic
</Item>
<Item key="Emp">
Empire
</Item>
</TabList>
<TabPanels>
<Item key="FoR">
<Text>
Arma virumque
cano, Troiae
qui primus ab
oris.
</Text>
</Item>
<Item key="MaR">
<Text>
Senatus
Populusque
Romanus.
</Text>
</Item>
<Item key="Emp">
<Text>
Alea jacta est.
</Text>
</Item>
</TabPanels>
</Tabs>Content#
Tabs expects a TabList and TabPanels as children. In turn, TabList and TabPanels follow the Collection Components API, accepting both static and dynamic collections. TabList and TabPanel accepts <Item> elements as children,
each with a key prop. The key passed to the TabList <Item> must match its corresponding TabPanel <Item>.
Static collections, as in this example, can be used when the full list of tabs and their contents is known ahead of time.
Dynamic collections, as shown below, can be used when the options come from an external data source such as an API call, or update over time. As seen below, an iterable list of options is passed to the Tabs using the items prop.
Each item accepts a key prop, which is passed to the onSelectionChange handler to identify the selected item. Alternatively, if the item objects contain an id property, as shown in the example below, then this is used automatically and a key prop is not required.
See the Events section for more detail on selection.
function Example() {
let tabs = [
{
id: 1
name: 'Founding of Rome'
children: 'Arma virumque cano, Troiae qui primus ab oris.'
}
{
id: 2
name: 'Monarchy and Republic'
children: 'Senatus Populusque Romanus.'
}
{id: 3 name: 'Empire' children: 'Alea jacta est.'}
];
let [tabId setTabId] = ReactuseState(1);
return (
<>
<p>Current tab id: tabId</p>
<Tabs
aria-label="History of Ancient Rome"
items=tabs
onSelectionChange=setTabId>
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
function Example() {
let tabs = [
{
id: 1
name: 'Founding of Rome'
children:
'Arma virumque cano, Troiae qui primus ab oris.'
}
{
id: 2
name: 'Monarchy and Republic'
children: 'Senatus Populusque Romanus.'
}
{id: 3 name: 'Empire' children: 'Alea jacta est.'}
];
let [tabId setTabId] = ReactuseState(1);
return (
<>
<p>Current tab id: tabId</p>
<Tabs
aria-label="History of Ancient Rome"
items=tabs
onSelectionChange=setTabId>
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
function Example() {
let tabs = [
{
id: 1
name:
'Founding of Rome'
children:
'Arma virumque cano, Troiae qui primus ab oris.'
}
{
id: 2
name:
'Monarchy and Republic'
children:
'Senatus Populusque Romanus.'
}
{
id: 3
name: 'Empire'
children:
'Alea jacta est.'
}
];
let [
tabId
setTabId
] = ReactuseState(1);
return (
<>
<p>
Current tab id:' '
tabId
</p>
<Tabs
aria-label="History of Ancient Rome"
items=tabs
onSelectionChange=
setTabId
>
<TabList>
(item) => (
<Item>
<Text>
itemname
</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>
itemchildren
</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
Internationalization#
To internationalize Tabs, a localized string should be passed as children to the TabList Item. Any text content within the Tab's panel should also be localized accordingly. For languages that are read right-to-left (e.g. Hebrew and Arabic), the layout of Tabs is automatically flipped.
Labeling#
Accessibility#
While an aria-label is not explicitly required for a tab list, Tabs should be labeled using a aria-label in the absence of an ancestor landmark.
This will prevent screen readers from announcing non-focused tabs, allowing for a more focused experience.
Selection#
Setting a selected tab can be done by using the defaultSelectedKey or selectedKey prop. The selected key corresponds to the key of an item. See Events for more details on selection events.
function Example() {
let tabs = [
{id: 1 name: 'Keyboard Settings' children: 'No keyboard detected.'}
{id: 2 name: 'Mouse Settings' children: 'No mouse detected.'}
{id: 3 name: 'Gamepad Settings' children: 'No gamepad detected'}
];
let [tab setTab] = ReactuseState(2);
return (
<Flex gap="size-150" wrap>
<span id="label-2">Settings (uncontrolled)</span>
<Tabs
aria-labelledby="label-2"
items=tabs
defaultSelectedKey=2
marginBottom="size-400">
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
<span id="label-3">Settings (controlled)</span>
<Tabs
aria-labelledby="label-3"
items=tabs
selectedKey=tab
onSelectionChange=setTab>
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</Flex>
);
}
function Example() {
let tabs = [
{
id: 1
name: 'Keyboard Settings'
children: 'No keyboard detected.'
}
{
id: 2
name: 'Mouse Settings'
children: 'No mouse detected.'
}
{
id: 3
name: 'Gamepad Settings'
children: 'No gamepad detected'
}
];
let [tab setTab] = ReactuseState(2);
return (
<Flex gap="size-150" wrap>
<span id="label-2">Settings (uncontrolled)</span>
<Tabs
aria-labelledby="label-2"
items=tabs
defaultSelectedKey=2
marginBottom="size-400">
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
<span id="label-3">Settings (controlled)</span>
<Tabs
aria-labelledby="label-3"
items=tabs
selectedKey=tab
onSelectionChange=setTab>
<TabList>
(item) => (
<Item>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</Flex>
);
}
function Example() {
let tabs = [
{
id: 1
name:
'Keyboard Settings'
children:
'No keyboard detected.'
}
{
id: 2
name:
'Mouse Settings'
children:
'No mouse detected.'
}
{
id: 3
name:
'Gamepad Settings'
children:
'No gamepad detected'
}
];
let [
tab
setTab
] = ReactuseState(2);
return (
<Flex
gap="size-150"
wrap>
<span id="label-2">
Settings
(uncontrolled)
</span>
<Tabs
aria-labelledby="label-2"
items=tabs
defaultSelectedKey=
2
marginBottom="size-400">
<TabList>
(item) => (
<Item>
<Text>
itemname
</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>
itemchildren
</Text>
</Item>
)
</TabPanels>
</Tabs>
<span id="label-3">
Settings
(controlled)
</span>
<Tabs
aria-labelledby="label-3"
items=tabs
selectedKey=tab
onSelectionChange=
setTab
>
<TabList>
(item) => (
<Item>
<Text>
itemname
</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item>
<Text>
itemchildren
</Text>
</Item>
)
</TabPanels>
</Tabs>
</Flex>
);
}
Events#
Tabs supports selection via mouse, keyboard, and touch. You can handle all of these via the onSelectionChange prop. Tabs will pass the selected key to the onSelectionChange handler.
The following example uses an onSelectionChange handler to update the tab selection stored in React state.
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
let [timePeriod setTimePeriod] = ReactuseState('Triassic');
return (
<>
<p>Selected time period: timePeriod</p>
<Tabs
aria-label="Mesozoic time periods"
items=tabs
selectedKey=timePeriod
onSelectionChange=setTimePeriod>
<TabList>
(item) => (
<Item key=itemname>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item key=itemname>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
let [timePeriod setTimePeriod] = ReactuseState(
'Triassic'
);
return (
<>
<p>Selected time period: timePeriod</p>
<Tabs
aria-label="Mesozoic time periods"
items=tabs
selectedKey=timePeriod
onSelectionChange=setTimePeriod>
<TabList>
(item) => (
<Item key=itemname>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item key=itemname>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
let [
timePeriod
setTimePeriod
] = ReactuseState(
'Triassic'
);
return (
<>
<p>
Selected time
period:' '
timePeriod
</p>
<Tabs
aria-label="Mesozoic time periods"
items=tabs
selectedKey=
timePeriod
onSelectionChange=
setTimePeriod
>
<TabList>
(item) => (
<Item
key=
itemname
>
<Text>
itemname
</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item
key=
itemname
>
<Text>
itemchildren
</Text>
</Item>
)
</TabPanels>
</Tabs>
</>
);
}
Keyboard Activation#
By default, pressing the arrow keys while focus is on a Tab will switch selection to the adjacent Tab in that direction, updating the content displayed accordingly. If you would like to prevent selection change
from happening automatically you can set the keyboardActivation prop to "manual". This will prevent tab selection from changing on arrow key press, requiring a subsequent Enter or Space key press to confirm
tab selection.
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
return (
<Tabs
aria-label="Mesozoic time periods"
items=tabs
keyboardActivation="manual">
<TabList>
(item) => (
<Item key=itemname>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item key=itemname>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
);
}
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
return (
<Tabs
aria-label="Mesozoic time periods"
items=tabs
keyboardActivation="manual">
<TabList>
(item) => (
<Item key=itemname>
<Text>itemname</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item key=itemname>
<Text>itemchildren</Text>
</Item>
)
</TabPanels>
</Tabs>
);
}
function Example() {
let tabs = [
{
name: 'Triassic'
children:
'The Triassic ranges roughly from 252 million to 201 million years ago, preceding the Jurassic Period.'
}
{
name: 'Jurassic'
children:
'The Jurassic ranges from 200 million years to 145 million years ago.'
}
{
name: 'Cretaceous'
children:
'The Cretaceous is the longest period of the Mesozoic, spanning from 145 million to 66 years ago.'
}
];
return (
<Tabs
aria-label="Mesozoic time periods"
items=tabs
keyboardActivation="manual">
<TabList>
(item) => (
<Item
key=
itemname
>
<Text>
itemname
</Text>
</Item>
)
</TabList>
<TabPanels>
(item) => (
<Item
key=
itemname
>
<Text>
itemchildren
</Text>
</Item>
)
</TabPanels>
</Tabs>
);
}
Props#
Visual options#
Density#
<Tabs aria-label="Chat log density example" density="compact">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs><Tabs
aria-label="Chat log density example"
density="compact">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs><Tabs
aria-label="Chat log density example"
density="compact">
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no
prior chat
history with
John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no
prior chat
history with
Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no
prior chat
history with
Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>Quiet#
<Tabs aria-label="Chat log quiet example" isQuiet>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs><Tabs aria-label="Chat log quiet example" isQuiet>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs><Tabs
aria-label="Chat log quiet example"
isQuiet>
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no
prior chat
history with
John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no
prior chat
history with
Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no
prior chat
history with
Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>Disabled#
<Flex direction="column" rowGap="size-150">
<Tabs
aria-label="Chat log single tab disabled example"
disabledKeys=['item2']>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs>
<Tabs aria-label="Chat log all tabs disabled example" isDisabled>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs>
</Flex><Flex direction="column" rowGap="size-150">
<Tabs
aria-label="Chat log single tab disabled example"
disabledKeys=['item2']>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
<Tabs
aria-label="Chat log all tabs disabled example"
isDisabled>
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
</Flex><Flex
direction="column"
rowGap="size-150">
<Tabs
aria-label="Chat log single tab disabled example"
disabledKeys=[
'item2'
]>
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no
prior chat
history with
John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no
prior chat
history with
Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no
prior chat
history with
Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
<Tabs
aria-label="Chat log all tabs disabled example"
isDisabled>
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no
prior chat
history with
John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no
prior chat
history with
Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no
prior chat
history with
Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
</Flex>Orientation#
<Tabs aria-label="Chat log orientation example" orientation="vertical">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs><Tabs
aria-label="Chat log orientation example"
orientation="vertical">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs><Tabs
aria-label="Chat log orientation example"
orientation="vertical">
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no
prior chat
history with
John Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no
prior chat
history with
Jane Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no
prior chat
history with
Joe Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>Collapse (overflow behavior)#
If there isn't enough horizontal room to render every tab on a single line, the component will collapse all tabs into a Picker. Note that this does not apply to vertical Tabs.
Try the example below to see the above behavior.
function Example() {
let [collapse setCollapse] = ReactuseState(false);
return (
<>
<div
style={
width: collapse ? '150px' : '300px'
marginBottom: '50px'
height: '150px'
maxWidth: '100%'
}>
<Tabs aria-label="Chat log collapse example">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>There is no prior chat history with John Doe.</Text>
</Item>
<Item key="item2">
<Text>There is no prior chat history with Jane Doe.</Text>
</Item>
<Item key="item3">
<Text>There is no prior chat history with Joe Bloggs.</Text>
</Item>
</TabPanels>
</Tabs>
</div>
<Button
variant="primary"
onPress=() => setCollapse((collapse) => !collapse)>
Toggle tab container size.
</Button>
</>
);
}
function Example() {
let [collapse setCollapse] = ReactuseState(false);
return (
<>
<div
style={
width: collapse ? '150px' : '300px'
marginBottom: '50px'
height: '150px'
maxWidth: '100%'
}>
<Tabs aria-label="Chat log collapse example">
<TabList>
<Item key="item1">
<Text>John Doe</Text>
</Item>
<Item key="item2">
<Text>Jane Doe</Text>
</Item>
<Item key="item3">
<Text>Joe Bloggs</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is no prior chat history with John
Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is no prior chat history with Jane
Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is no prior chat history with Joe
Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
</div>
<Button
variant="primary"
onPress=() =>
setCollapse((collapse) => !collapse)
>
Toggle tab container size.
</Button>
</>
);
}
function Example() {
let [
collapse
setCollapse
] = ReactuseState(
false
);
return (
<>
<div
style={
width: collapse
? '150px'
: '300px'
marginBottom:
'50px'
height:
'150px'
maxWidth:
'100%'
}>
<Tabs aria-label="Chat log collapse example">
<TabList>
<Item key="item1">
<Text>
John Doe
</Text>
</Item>
<Item key="item2">
<Text>
Jane Doe
</Text>
</Item>
<Item key="item3">
<Text>
Joe
Bloggs
</Text>
</Item>
</TabList>
<TabPanels>
<Item key="item1">
<Text>
There is
no prior
chat
history
with John
Doe.
</Text>
</Item>
<Item key="item2">
<Text>
There is
no prior
chat
history
with Jane
Doe.
</Text>
</Item>
<Item key="item3">
<Text>
There is
no prior
chat
history
with Joe
Bloggs.
</Text>
</Item>
</TabPanels>
</Tabs>
</div>
<Button
variant="primary"
onPress=() =>
setCollapse(
(collapse) =>
!collapse
)
>
Toggle tab
container size.
</Button>
</>
);
}