This library is still in development and is available only for internal usage at VTEX.
Skip to main content

Tabs

Version: 0.131.0

Tabs

Tabs are navigation solutions for alternating between content that is at the same level of the hierarchy.

Examples​

Fluid​

This property will make the TabList, match the container width. By default, it has the value set to false.

function Example() {
const state = useTabState()

return (
<Tabs state={state}>
<TabList fluid aria-label="fluid-tabs">
<Tab id="1">Tab 1</Tab>
<Tab id="2">Tab 2</Tab>
<Tab id="3">Tab 3</Tab>
<Tab id="4">Tab 4</Tab>
</TabList>
<TabPanel id="1" csx={{ padding: 3 }}>
Tab 1
</TabPanel>
<TabPanel id="2" csx={{ padding: 3 }}>
Tab 2
</TabPanel>
<TabPanel id="3" csx={{ padding: 3 }}>
Tab 3
</TabPanel>
<TabPanel id="4" csx={{ padding: 3 }}>
Tab 4
</TabPanel>
</Tabs>
)
}

Default selected tab​

You can set the default selected tab by passing an id to selectedId on useTabState.

function Example() {
const state = useTabState({ selectedId: '2' })

return (
<Tabs state={state}>
<TabList fluid aria-label="my-tabs">
<Tab id="1">Tab 1</Tab>
<Tab id="2">Tab 2</Tab>
<Tab id="3">Tab 3</Tab>
</TabList>
<TabPanel id="1" csx={{ padding: 3 }}>
Tab 1
</TabPanel>
<TabPanel id="2" csx={{ padding: 3 }}>
Tab 2
</TabPanel>
<TabPanel id="3" csx={{ padding: 3 }}>
Tab 3
</TabPanel>
</Tabs>
)
}

Select a Tab manually​

You can set the selected tab by passing an id to the select returned by the useTabState.

function Example() {
const state = useTabState()

return (
<Tabs state={state}>
<TabList fluid aria-label="my-tabs">
<Tab id="1">Tab 1</Tab>
<Tab id="2">Tab 2</Tab>
</TabList>
<TabPanel id="1" csx={{ padding: 3 }}>
<Button onClick={() => state.select('2')}>Go to Tab 2!</Button>
</TabPanel>
<TabPanel id="2" csx={{ padding: 3 }}>
<Button onClick={() => state.select('1')}>Go to Tab 1!</Button>
</TabPanel>
</Tabs>
)
}

Manual Activation​

By default, a Tab is selected when it gets focused, which reveals its corresponding TabPanel. This behavior can be changed by setting manual to true on useTabState.

function Example() {
const state = useTabState({ manual: true })

return (
<Tabs state={state}>
<TabList fluid aria-label="my-tabs">
<Tab id="1">Tab 1</Tab>
<Tab id="2">Tab 2</Tab>
</TabList>
<TabPanel id="1" csx={{ padding: 3 }}>
Tab 1
</TabPanel>
<TabPanel id="2" csx={{ padding: 3 }}>
Tab 2
</TabPanel>
</Tabs>
)
}