Tabs

Tabs make it easy to explore and switch between different views.

() => {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
value={value}
aria-label="tabs"
>
<Tab label="Section1" disableFocusRipple />
<Tab label="Section2" disableFocusRipple />
<Tab label="Section4" disableFocusRipple />
<Tab label="Section5" disableFocusRipple />
<Tab label="Section6" disableFocusRipple />
<Tab label="Section7" disableFocusRipple />
</Tabs>
);
};

Props

PropTypeDefaultDescription
actionrefCallback fired when the component mounts. This is useful when you want to trigger an action programmatically. It supports two actions: updateIndicator() and updateScrollButtons()
aria-labelstringThe label for the Tabs as a string.
aria-labelledbystringAn id or list of ids separated by a space that label the Tabs.
aria-describedbystringIdentifies the element (or elements) that describes the element on which the attribute is set.
centeredboolfalseIf true, the tabs are centered. This prop is intended for large views.
childrennodeThe content of the component.
classesobjectobject
onChangefuncCallback fired when the value changes.
orientationhorizontal | verticalhorizontalThe component orientation (layout flow direction).
scrollButtonsauto | true | falseautoDetermine behavior of scroll buttons when tabs are set to scroll: 'auto' will only present them when not all the items are visible. 'true' will always present them. 'false' will never present them.
ScrollButtonComponentelementTypeTabScrollButtonThe component used to render the scroll buttons.
selectionFollowsFocusboolIf true the selected tab changes on focus. Otherwise it only changes on activation.
slotProps{ endScrollButtonIcon?: func | object, startScrollButtonIcon?: func | object }{}The extra props for the slot components. You can override the existing props or add new ones.
slots{ EndScrollButtonIcon?: elementType, StartScrollButtonIcon?: elementType }{}The components used for each slot inside.
sxArrayThe system prop that allows defining system overrides as well as additional CSS styles.
TabIndicatorPropsobject{}Props applied to the tab indicator element.
textColor0primaryDetermines the color of the Tab
valueanyThe value of the currently selected Tab. If you do not want any selected Tab, you can set this prop to false.
variantfullWidth | scrollable | standardstandardDetermines additional display behavior of tabs: 'scrollable' will invoke scrolling properties and allow for horizontally scrolling (or swiping) of the tab bar. 'fullWidth' will make the tabs grow to use all the available space, which should be used for small views, like on mobile. 'standard' will render the default state.
visibleScrollbarboolfalseIf true, the scrollbar is visible. It can be useful when displaying a long vertical list of tabs.

The first tab will be active by default

() => {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs onChange={handleChange} value={value} aria-label="tabs">
<Tab label="Section1" disableFocusRipple />
<Tab label="Section2" disableFocusRipple />
<Tab label="Section3" disableFocusRipple />
</Tabs>
);
};

None of the tabs will be active by default

() => {
const [value, setValue] = React.useState(null);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs onChange={handleChange} value={value} aria-label="tabs">
<Tab label="Section1" disableFocusRipple />
<Tab label="Section2" disableFocusRipple />
<Tab label="Section3" disableFocusRipple />
</Tabs>
);
};

Includes tooltips with badges

Technically it is button, but this is to make it accessible with the keyboard

() => {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
const [openToolTipId, setOpenToolTipId] = React.useState(null);
const handleTooltipClose = () => {
setOpenToolTipId(null);
};
const handleTooltipOpen = (id) => {
setOpenToolTipId(id);
};
const tabLabel = (tab, amount) => {
return (
<div>
<span style={{marginRight: '4px'}}>{tab}</span>
<>
<Tooltip
title="Bad things"
placement="top"
disableInteractive
disableFocusListener
onClose={handleTooltipClose}
open={openToolTipId === 'bad'}
>
<Button
color="error"
size="small"
data-testid="bad-count"
onFocus={() => {
handleTooltipOpen('bad');
}}
onBlur={() => {
handleTooltipClose();
}}
onMouseOver={() => {
handleTooltipOpen('bad');
}}
sx={{
minWidth: '28px',
padding: '0',
minHeight: '18px',
fontSize: '12px',
border: 'none',
marginRight: '4px',
}}
>
{amount}
</Button>
</Tooltip>
<Tooltip
title="Good things"
placement="top"
disableInteractive
disableFocusListener
onClose={handleTooltipClose}
open={openToolTipId === 'good'}
>
<Button
color="success"
size="small"
data-testid="good-count"
onFocus={() => {
handleTooltipOpen('good');
}}
onBlur={() => {
handleTooltipClose();
}}
onMouseOver={() => {
handleTooltipOpen('good');
}}
sx={{
minWidth: '28px',
padding: '0',
minHeight: '18px',
fontSize: '12px',
border: 'none',
}}
>
{amount - 40}
</Button>
</Tooltip>
</>
</div>
);
};
return (
<Tabs onChange={handleChange} value={value} aria-label="tabs">
<Tab label={tabLabel('Section1', 134)} disableFocusRipple />
<Tab label="Section2" disableFocusRipple />
<Tab label="Section3" disableFocusRipple />
</Tabs>
);
};