TabLine
Try resizing the page to see how the tabs adjust. If the text in a tab is too long, it will be truncated with an ellipsis
. You can also place the TabLine.Item
within other components.
INFO
Make sure to provide a tooltip with full text for tabs with text truncated with an ellipsis
.
TabLine item with addons
You can add icons, badges, and counters as addons to the left or right of the text in the item.
import Badge from '@semcore/badge';
import FacebookM from '@semcore/icon/Facebook/m';
import InstagramM from '@semcore/icon/Instagram/m';
import TwitterM from '@semcore/icon/Twitter/m';
import TabLine from '@semcore/tab-line';
import React from 'react';
const Demo = () => {
const [value, setValue] = React.useState(1);
return (
<>
<TabLine value={value} onChange={setValue} aria-label='Social network reports'>
<TabLine.Item
value={1}
aria-controls={value === 1 ? 'tab-panel-4-1' : undefined}
id='tab-label-4-1'
>
<TabLine.Item.Addon>
<FacebookM />
</TabLine.Item.Addon>
<TabLine.Item.Text>Facebook</TabLine.Item.Text>
</TabLine.Item>
<TabLine.Item
value={2}
aria-controls={value === 2 ? 'tab-panel-4-2' : undefined}
id='tab-label-4-2'
>
<TabLine.Item.Addon>
<InstagramM />
</TabLine.Item.Addon>
<TabLine.Item.Text>Instagram</TabLine.Item.Text>
<TabLine.Item.Addon>
<Badge bg='green-400'>new</Badge>
</TabLine.Item.Addon>
</TabLine.Item>
<TabLine.Item
value={3}
aria-controls={value === 3 ? 'tab-panel-4-3' : undefined}
id='tab-label-4-3'
>
<TabLine.Item.Addon>
<TwitterM />
</TabLine.Item.Addon>
<TabLine.Item.Text>Twitter</TabLine.Item.Text>
</TabLine.Item>
</TabLine>
{
[
<div key='tab-panel-4-1' id='tab-panel-4-1' role='tabpanel' aria-labelledby='tab-label-4-1' tabIndex={-1}>
<h3>Facebook</h3>
<p>
It's where your aunt's cat has more followers than you, and your high school nemesis
still thinks they're relevant.
</p>
</div>,
<div
key='tab-panel-4-2'
id='tab-panel-4-2'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-4-2'
tabIndex={-1}
>
<h3>Instagram</h3>
<p>
It's where people spend hours perfecting their avocado toast just for a 'like', and
your explore page thinks you need therapy based on your search history.
</p>
</div>,
<div
key='tab-panel-4-3'
id='tab-panel-4-3'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-4-3'
tabIndex={-1}
>
<h3>Twitter</h3>
<p>
It's where 280 characters can start a revolution or a feud over pineapple on pizza,
and your timeline is a mix of breaking news and cat memes.
</p>
</div>,
][value - 1]
}
</>
);
};
export default Demo;
Disabled TabLine item
Use disabled
property to make <TabLine.Item />
disabled. Always add Tooltip
to explain why this item is disabled.
import TabLine from '@semcore/tab-line';
import Tooltip from '@semcore/tooltip';
import React from 'react';
const Demo = () => {
const [value, setValue] = React.useState(1);
return (
<>
<TabLine value={value} onChange={setValue} aria-label='Social network reports'>
<TabLine.Item
value={1}
aria-controls={value === 1 ? 'tab-panel-2-1' : undefined}
id='tab-label-2-1'
>
<TabLine.Item.Text>Normal tab</TabLine.Item.Text>
</TabLine.Item>
<Tooltip
title='Do not forget to add short text to explain why this item is disabled.'
placement='top'
role='tab'
>
<TabLine.Item value={2} disabled>
<TabLine.Item.Text>Disabled tab</TabLine.Item.Text>
</TabLine.Item>
</Tooltip>
</TabLine>
{
[
<div key='2-1' id='tab-panel-2-1' role='tabpanel' aria-labelledby='tab-label-2-1' tabIndex={-1}>
<h3>Normal tab</h3>
<p>
Here you can place your content, or just leave it blank for that avant-garde
minimalist vibe.
</p>
</div>,
][value - 1]
}
</>
);
};
export default Demo;
Automatic tab activation
By default, tabs are switched automatically when selected.
import TabLine from '@semcore/tab-line';
import React from 'react';
const Demo = () => {
const [value, setValue] = React.useState(1);
return (
<>
<TabLine onChange={setValue} value={value} aria-label='Animals'>
<TabLine.Item
value={1}
aria-controls={value === 1 ? 'tab-panel-1-1' : undefined}
id='tab-label-1-1'
>
Cats
</TabLine.Item>
<TabLine.Item
value={2}
aria-controls={value === 2 ? 'tab-panel-1-2' : undefined}
id='tab-label-1-2'
>
Dogs
</TabLine.Item>
<TabLine.Item
value={3}
aria-controls={value === 3 ? 'tab-panel-1-3' : undefined}
id='tab-label-1-3'
>
Birds
</TabLine.Item>
</TabLine>
{
[
<div key='tab-panel-1-1' id='tab-panel-1-1' role='tabpanel' aria-labelledby='tab-label-1-1' tabIndex={-1}>
<h3>Cats</h3>
<p>
They are the only creatures that can simultaneously demand your attention and ignore
you completely, while plotting world domination from the top of the refrigerator.
</p>
</div>,
<div
key='tab-panel-1-2'
id='tab-panel-1-2'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-1-2'
tabIndex={-1}
>
<h3>Dogs</h3>
<p>
They are the eternal optimists who believe that every stranger is a potential friend
and every walk is an adventure, even if it's just to the mailbox.
</p>
</div>,
<div
key='tab-panel-1-3'
id='tab-panel-1-3'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-1-3'
tabIndex={-1}
>
<h3>Birds</h3>
<p>
They are the tiny dinosaurs who sing like they're auditioning for Broadway and have a
knack for leaving 'gifts' on freshly washed cars.
</p>
</div>,
][value - 1]
}
</>
);
};
export default Demo;
Manual tab activation
You can set behavior='manual'
on TabLine to change the tab activation method to manual.
import TabLine from '@semcore/tab-line';
import React from 'react';
const Demo = () => {
const [value, setValue] = React.useState(1);
return (
<>
<TabLine onChange={setValue} value={value} behavior='manual' aria-label='Animals'>
<TabLine.Item
value={1}
aria-controls={value === 1 ? 'tab-panel-3-1' : undefined}
id='tab-label-3-1'
>
Cats
</TabLine.Item>
<TabLine.Item
value={2}
aria-controls={value === 2 ? 'tab-panel-3-2' : undefined}
id='tab-label-3-2'
>
Dogs
</TabLine.Item>
<TabLine.Item
value={3}
aria-controls={value === 3 ? 'tab-panel-3-3' : undefined}
id='tab-label-3-3'
>
Birds
</TabLine.Item>
</TabLine>
{
[
<div key='tab-panel-3-1' id='tab-panel-3-1' role='tabpanel' aria-labelledby='tab-label-3-1' tabIndex={-1}>
<h3>Cats</h3>
<p>
They are the only creatures that can simultaneously demand your attention and ignore
you completely, while plotting world domination from the top of the refrigerator.
</p>
</div>,
<div
key='tab-panel-3-2'
id='tab-panel-3-2'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-3-2'
tabIndex={-1}
>
<h3>Dogs</h3>
<p>
They are the eternal optimists who believe that every stranger is a potential friend
and every walk is an adventure, even if it's just to the mailbox.
</p>
</div>,
<div
key='tab-panel-3-3'
id='tab-panel-3-3'
aria-hidden='true'
role='tabpanel'
aria-labelledby='tab-label-3-3'
tabIndex={-1}
>
<h3>Birds</h3>
<p>
They are the tiny dinosaurs who sing like they're auditioning for Broadway and have a
knack for leaving 'gifts' on freshly washed cars.
</p>
</div>,
][value - 1]
}
</>
);
};
export default Demo;
Custom indents
Since the TabLine component doesn't have default margins at the edges, to make it fill the entire width of its parent block (which may have its own margins), you can set the desired padding
and margin
for the TabLine component like this:
<Box p={5}>
<TabLine px={5} mx="-20px" />
</Box>