Skip to main content

Tabs

Quick start

Here's a quick start guide to get started with the Tabs component

Importing Component

import { Tabs } from "@hover-design/react";

Code Snippets and Examples

Tabs Default
const tabsData = [
{
label: "First",
value: "first"
},
{
label: "Second",
value: "second",
disabled: true
},
{
label: "Third",
value: "third",
icon: <FiArrowRightCircle />
},
{
label: "Fourth",
value: "fourth",
icon: <FiCpu />,
badge: "13"
}
];

<div className="App">
<Tabs defaultValue={"first"} tabsData={tabsData}>
{(selectedTab) => <div>{selectedTab.label}</div>}
</Tabs>
</div>;

(selectedTab) contains the whole tab object which is selected.

Tabs Vertical
const tabsData = [
{
label: "First",
value: "first"
},
{
label: "Second",
value: "second",
disabled: true
},
{
label: "Third",
value: "third",
icon: <FiArrowRightCircle />
},
{
label: "Fourth",
value: "fourth",
icon: <FiCpu />,
badge: "13"
}
];

<div className="App">
<Tabs
defaultValue={"first"}
tabSize={"200px"}
textAlign={"left"}
orientation={"vertical"}
tabsData={tabsData}
>
{(selectedTab) => <div>{selectedTab.label}</div>}
</Tabs>
</div>;

(selectedTab) contains the whole tab object which is selected.

Tabs Variants - Outline
const tabsData = [
{
label: "First",
value: "first"
},
{
label: "Second",
value: "second",
disabled: true
},
{
label: "Third",
value: "third",
icon: <FiArrowRightCircle />
},
{
label: "Fourth",
value: "fourth",
icon: <FiCpu />,
badge: "13"
}
];

<div className="App">
<Tabs defaultValue={"first"} variant={"outline"} tabsData={tabsData}>
{(selectedTab) => <div>{selectedTab.label}</div>}
</Tabs>
</div>;

(selectedTab) contains the whole tab object which is selected.

Tabs Variants - Pill
const tabsData = [
{
label: "First",
value: "first"
},
{
label: "Second",
value: "second",
disabled: true
},
{
label: "Third",
value: "third",
icon: <FiArrowRightCircle />
},
{
label: "Fourth",
value: "fourth",
icon: <FiCpu />,
badge: "13"
}
];

<div className="App">
<Tabs defaultValue={"first"} variant={"pill"} tabsData={tabsData}>
{(selectedTab) => <div>{selectedTab.label}</div>}
</Tabs>
</div>;

(selectedTab) contains the whole tab object which is selected.

Controlled Tabs
const [activeTab, setActiveTab] = useState("first");

const tabsData = [
{
label: "First",
value: "first"
},
{
label: "Second",
value: "second",
disabled: true
},
{
label: "Third",
value: "third",
icon: <FiArrowRightCircle />
},
{
label: "Fourth",
value: "fourth",
icon: <FiCpu />,
badge: "15"
}
];

<div className="App">
<Tabs
value={activeTab}
onChange={(selectedTab) => setActiveTab(selectedTab.value)}
value
tabsData={tabsData}
>
{(selectedTab) => <div>{selectedTab.label}</div>}
</Tabs>
</div>;

(tabsData) contains the whole tab object which is selected.

Props Reference

AttributesValuesDefault ValueOptional ?
defaultValue must be equal to value from Tabs Object
string | number
Yes
value must be equal to value from Tabs Object
string | number
Yes
orientationhorizontal | verticalhorizontalYes
variantdefault | outline | pilldefaultYes
colorstring#2F80EDYes
backgroundColorstring#d7e9ffYes
outlineColorstring#EBECF0Yes
textAlignleft | center| rightcenterYes
roundnessstring4pxYes
onChange(selectedTabObject)=>void()=>{}Yes
growgrows to fit the containter booleanfalseYes
size height for horizontal & width for vertical
string
40pxYes
tabsDataArray of Tabs ObjectNo
children not a prop but children to the <Tabs/>
(selectedTabObject)=> JSX
No

Tabs Object

KeytypeOptional ?
labelstringNo
valuestring | numberNo
iconJSX ElementYes
disabledbooleanYes
badgestring | JSX ElementYes
refMutableRefObject<HTMLDivElement>Yes

Keyboard Controls

Keyboard controls will only work when the Tab is focused (selected)

KeytypeOrientation
ArrowRightNext Tabhorizontal
ArrowLeftPrevious Tabhorizontal
ArrowDownNext Tabvertical
ArrowUpPrevious Tabvertical
Home if not disabled
First Tab
both
End if not disabled
Last Tab
both