Tabs
Tabs organize related content into distinct sections and provide users with a navigational interface to switch between these sections.
Basic
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Controlled
- To control Tabs state, use
selectedIndexandonChangeprops:
Source Code
import * as React from 'react';
import { Tabs, TabHeader, TabList, TabListItem, TabPanels, TabPanel } from '@ocean-network-express/magenta-ui/react';
function Demo() {
const [selectedIndex, setSelectedIndex] = React.useState<number>(0);
return (
<Tabs selectedIndex={selectedIndex} onChange={setSelectedIndex}>
<TabHeader>
<TabList>Uncontrolled
- If you do not need to subscribe to Tabs state changes, use
defaultValue:
Source Code
import * as React from 'react';
import { Tabs, TabHeader, TabList, TabListItem, TabPanels, TabPanel } from '@ocean-network-express/magenta-ui/react';
function Demo() {
return (
<Tabs defaultIndex={0}>
<TabHeader>
<TabList>
<TabListItem>Tab 1</TabListItem>
<TabListItem>Tab 2</TabListItem>Disabled Tabs
- To disable a tab, pass the
disabledprop to theTabListItemcomponent.
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Sizes
- Tabs supports 4 sizes
sm,md,lgandresponsiveand can be changed by passing thesizeprop. - Default size is
lg.
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,- With size
responsive, the component will be responsive to the viewport.
Screen prefix | Screen width | Component size |
|---|---|---|
xs → xl | 0px → 1279px | sm |
xl → 3xl | 1280px → 1919px | md |
3xl → ∞ | 1920px → ∞ | lg |
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Tabs Variants
Horizontal
- Tabs supports 2 variant
horizontalandvertical. - Default variant is
horizontal.
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Vertical
- Pass the
verticalprop to change the variant.
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Scrollable
- Tabs supports scrollable by pass the
controlprop.
Horizontal
Source Code
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,
Text,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';
import { TabItems } from '../../utils/Tabs/helpers';Vertical
Source Code
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,
Text,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';
import { TabItems } from '../../utils/Tabs/helpers';Deletable
TabListItemcan have a close icon by passing thedeletableprop to theTabcomponent.- The close icon will be displayed on the right side of the tab when
TabListItemis hovered or selected. - Passing the
onDeleteprop to theTabcomponent to handle the close icon clicked event.
Total: 3
Source Code
import { AddOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,
Text,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';Custom Delete Icon
- You can customize the delete icon by passing the
deleteIconprop to theTabcomponent.
Total: 10
Source Code
import { AddOutline, CloseRemoveOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,
Text,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';Customize
Destroy Inactive Tabs
- By default, the content of inactive
TabPanelwill be destroyed. SetdestroyOnHidden={false}onTabsto allow the content to remain rendered.
Tab panel 1
Tab panel 2
Tab panel 3
Source Code
import {
TrainFrontOutline,
TruckFrontOutline,
VesselFrontOutline,
} from '@ocean-network-express/magenta-ui/icons';
import {
TabHeader,
TabList,
TabListItem,
TabPanel,
TabPanels,
Tabs,Accessibility
Tabs component follows WAI-ARIA recommendations on accessibility.
Keyboard interactions
Key | Description | Condition |
|---|---|---|
ArrowRight | Focuses and activates next tab that is not disabled | vertical="false" |
ArrowLeft | Focuses and activates previous tab that is not disabled | vertical="false" |
ArrowDown | Focuses and activates next tab that is not disabled | vertical="true" |
ArrowUp | Focuses and activates previous tab that is not disabled | vertical="true" |
Home | Focuses and activates first tab | |
End | Focuses and activates last tab |
Was this page helpful?
Tab Bar
Navigation Tabs
TabPanel
TabPanels
TabListItem
TabList
TabHeader
TabListGroup