Tabs is a component that makes navigating between sections of related content possible, displaying one section at a time.
Use Tabs if the content can be separated into sections that make sense as standalone pieces of information.
Be aware that the users will not see all the content at the same time. Make sure the first section is the most relevant one.
Import
import{ Tabs }from'@contentful/f36-components';
// or
import{ Tabs }from'@contentful/f36-tabs';
Examples
Basic
functionTabsBasicExample(){
return(
<Tabs>
<Tabs.List>
<Tabs.TabpanelId="first">First</Tabs.Tab>
<Tabs.TabpanelId="second">Second</Tabs.Tab>
<Tabs.TabpanelId="third">Third</Tabs.Tab>
</Tabs.List>
<Tabs.Panelid="first">Content for the first tab</Tabs.Panel>
<Tabs.Panelid="second">Content for the second tab</Tabs.Panel>
<Tabs.Panelid="third">Content for the third tab</Tabs.Panel>
</Tabs>
);
}
With divider
By default, Tabs has no divider, but you can add it by providing variant prop to the Tabs.List
With vertical divider:
functionTabsWithVerticalDividerExample(){
return(
<Tabs>
<Tabs.Listvariant="vertical-divider">
<Tabs.TabpanelId="first">First</Tabs.Tab>
<Tabs.TabpanelId="second">Second</Tabs.Tab>
<Tabs.TabpanelId="third">Third</Tabs.Tab>
</Tabs.List>
<Tabs.Panelid="first">Content for the first tab</Tabs.Panel>
<Tabs.Panelid="second">Content for the second tab</Tabs.Panel>
<Tabs.Panelid="third">Content for the third tab</Tabs.Panel>
</Tabs>
);
}
With horizontal divider:
functionTabsWithHorizontalDividerExample(){
return(
<Tabs>
<Tabs.Listvariant="horizontal-divider">
<Tabs.TabpanelId="first">First</Tabs.Tab>
<Tabs.TabpanelId="second">Second</Tabs.Tab>
<Tabs.TabpanelId="third">Third</Tabs.Tab>
</Tabs.List>
<Tabs.Panelid="first">Content for the first tab</Tabs.Panel>
<Tabs.Panelid="second">Content for the second tab</Tabs.Panel>
<Tabs.Panelid="third">Content for the third tab</Tabs.Panel>
</Tabs>
);
}
With default open tab
functionTabsWithDefaultTabExample(){
return(
<TabsdefaultTab="first">
<Tabs.List>
<Tabs.TabpanelId="first">First</Tabs.Tab>
<Tabs.TabpanelId="second">Second</Tabs.Tab>
<Tabs.TabpanelId="third">Third</Tabs.Tab>
</Tabs.List>
<Tabs.Panelid="first">Content for the first tab</Tabs.Panel>
<Tabs.Panelid="second">Content for the second tab</Tabs.Panel>
<Tabs.Panelid="third">Content for the third tab</Tabs.Panel>
</Tabs>
);
}
With disabled tab
functionTabsWithDefaultTabExample(){
return(
<Tabs>
<Tabs.List>
<Tabs.TabpanelId="first">First</Tabs.Tab>
<Tabs.TabpanelId="second">Second</Tabs.Tab>
<Tabs.TabpanelId="third"isDisabled>
Third(disabled)
</Tabs.Tab>
</Tabs.List>
<Tabs.Panelid="first">Content for the first tab</Tabs.Panel>
<Tabs.Panelid="second">Content for the second tab</Tabs.Panel>
<Tabs.Panelid="third">Content for the third tab</Tabs.Panel>
</Tabs>
);
}
Controlled Tabs
By default, Tabs is an uncontrolled component, but you can make it controlled by providing currentTab and onTabChange props.