Skip to content
+

Tabs

Tabs organize groups of related content and let users navigate between them.

useTab API

Import

import { useTab } from '@base_ui/react/Tabs';

Parameters

NameTypeDescription
disabledboolean

If true, the tab will be disabled.

idstring

The id of the tab. If not provided, it will be automatically generated.

onClickReact.MouseEventHandler

Callback fired when the tab is clicked.

rootRefReact.Ref<Element>

Ref to the root slot's DOM element.

valueany

The value of the tab. It's used to associate the tab with a tab panel(s) with the same value. If the value is not provided, it falls back to the position index.

Return value

NameTypeDescription
getRootProps(externalProps?: React.ComponentPropsWithRef<'button'>) => React.ComponentPropsWithRef<'button'>

Resolver for the root slot's props.

indexnumber

0-based index of the tab in the list of tabs.

orientationTabsOrientation
rootRefReact.RefCallback<Element> | null

Ref to the root slot's DOM element.

selectedboolean

If true, the tab is selected.

totalTabsCountnumber

Total number of tabs in the nearest parent TabsList. This can be used to determine if the tab is the last one to style it accordingly.


useTabIndicator API

Import

import { useTabIndicator } from '@base_ui/react/Tabs';
This hook does not accept any input parameters.

Return value

NameTypeDescription
activeTabPositionActiveTabPosition | null
directionTabsDirection
getRootProps(otherProps?: React.ComponentPropsWithRef<'span'>) => React.ComponentPropsWithRef<'span'>
orientationTabsOrientation
tabActivationDirectionTabActivationDirection

useTabPanel API

Import

import { useTabPanel } from '@base_ui/react/Tabs';

Parameters

NameTypeDescription
idstring

The id of the TabPanel.

rootRefReact.Ref<HTMLElement>

The ref of the TabPanel.

valueany

The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected.

Return value

NameTypeDescription
directionTabsDirection
getRootProps(externalProps?: React.ComponentPropsWithRef<'div'>) => React.ComponentPropsWithRef<'div'>

Resolver for the root slot's props.

hiddenboolean

If true, it indicates that the tab panel will be hidden.

orientationTabsOrientation
rootRefReact.RefCallback<HTMLElement> | null
tabActivationDirectionTabActivationDirection

useTabsList API

Import

import { useTabsList } from '@base_ui/react/Tabs';

Parameters

NameTypeDescription
activateOnFocus*boolean

If true, the tab will be activated whenever it is focused. Otherwise, it has to be activated by clicking or pressing the Enter or Space key.

loop*boolean

If true, using keyboard navigation will wrap focus to the other end of the list once the end is reached.

rootRef*React.Ref<Element>

Ref to the root element.

Return value

NameTypeDescription
contextValueTabsListProviderValue

The value to be passed to the TabListProvider above all the tabs.

directionTabsDirection

If true, it will indicate that the text's direction in right-to-left.

dispatch(action: ListAction<any>) => void

Action dispatcher for the tabs list component. Allows to programmatically control the tabs list.

getRootProps(externalProps?: React.ComponentPropsWithRef<'div'>) => React.ComponentPropsWithRef<'div'>

Resolver for the root slot's props.

highlightedValueany | null

The value of the currently highlighted tab.

orientationTabsOrientation

The component orientation (layout flow direction).

rootRefReact.RefCallback<Element> | null
selectedValueany | null

The value of the currently selected tab.

tabActivationDirectionTabActivationDirection

useTabsRoot API

Import

import { useTabsRoot } from '@base_ui/react/Tabs';
This hook does not accept any input parameters.

Return value

NameTypeDescription