Tabs
A component for toggling between related panels on the same page.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Tabs } from '@base-ui/react/tabs';
<Tabs.Root>
<Tabs.List>
<Tabs.Tab />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Panel />
</Tabs.Root>API reference
Root
Groups the tabs and the corresponding panels.
Renders a <div> element.
defaultValueTabs.Tab.Value0
Tabs.Tab.Value- Name
- Description
The default value. Use when the component is not controlled. When the value is
null, no Tab will be active.- Type
Tabs.Tab.Value | undefined- Default
0
valueTabs.Tab.Value—
Tabs.Tab.Value- Name
- Description
The value of the currently active
Tab. Use when the component is controlled. When the value isnull, no Tab will be active.- Type
Tabs.Tab.Value | undefined
onValueChangefunction—
function- Name
- Description
Callback invoked when new value is being set.
- Type
| (( value: Tabs.Tab.Value, eventDetails: Tabs.Root.ChangeEventDetails< 'none', { activationDirection: Tabs.Tab.ActivationDirection; } >, ) => void) | undefined
orientationTabs.Root.Orientation'horizontal'
Tabs.Root.Orientation- Name
- Description
The component orientation (layout flow direction).
- Type
Tabs.Root.Orientation | undefined- Default
'horizontal'
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Tabs.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Root.State, ) => ReactElement) | undefined
data-orientation
data-activation-direction
Additional Types
Tabs.Root.Props
Re-Export of Root props as TabsRootProps
Tabs.Root.State
type TabsRootState = {
orientation: Tabs.Root.Orientation;
tabActivationDirection: Tabs.Tab.ActivationDirection;
};Tabs.Root.ChangeEventReason
type TabsRootChangeEventReason = 'none';Tabs.Root.ChangeEventDetails
type TabsRootChangeEventDetails = {
reason: 'none';
event: Event;
cancel: () => void;
allowPropagation: () => void;
isCanceled: boolean;
isPropagationAllowed: boolean;
trigger: Element | undefined;
activationDirection: Tabs.Tab.ActivationDirection;
};Tabs.Root.Orientation
type TabsRootOrientation = 'horizontal' | 'vertical';List
Groups the individual tab buttons.
Renders a <div> element.
activateOnFocusbooleanfalse
boolean- Name
- Description
Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using Enter or Space key press.
- Type
boolean | undefined- Default
false
loopFocusbooleantrue
boolean- Name
- Description
Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
- Type
boolean | undefined- Default
true
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.List.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Tabs.List.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.List.State, ) => ReactElement) | undefined
data-orientation
data-activation-direction
Additional Types
Tabs.List.Props
Re-Export of List props as TabsListProps
Tabs.List.State
type TabsListState = {
orientation: Tabs.Root.Orientation;
tabActivationDirection: Tabs.Tab.ActivationDirection;
};Tab
An individual interactive tab button that toggles the corresponding panel.
Renders a <button> element.
value*Tabs.Tab.Value—
Tabs.Tab.Value- Name
- Description
The value of the Tab.
- Type
nativeButtonbooleantrue
boolean- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
boolean | undefined- Default
true
disabledboolean—
boolean- Name
- Description
Whether the Tab is disabled.
If a first Tab on a
<Tabs.List>is disabled, it won’t initially be selected. Instead, the next enabled Tab will be selected. However, it does not work like this during server-side rendering, as it is not known during pre-rendering which Tabs are disabled. To work around it, ensure thatdefaultValueorvalueon<Tabs.Root>is set to an enabled Tab’s value.- Type
boolean | undefined
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Tab.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Tabs.Tab.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Tab.State, ) => ReactElement) | undefined
data-orientation
data-disabled
data-activation-direction
data-active
Additional Types
Tabs.Tab.Props
Re-Export of Tab props as TabsTabProps
Tabs.Tab.State
type TabsTabState = { disabled: boolean; active: boolean; orientation: Tabs.Root.Orientation };Tabs.Tab.Value
type TabsTabValue = Tabs.Tab.Value;Tabs.Tab.ActivationDirection
type TabsTabActivationDirection = 'left' | 'right' | 'up' | 'down' | 'none';Tabs.Tab.Metadata
type TabsTabMetadata = {
disabled: boolean;
id: string | undefined;
value: Tabs.Tab.Value | undefined;
};Tabs.Tab.Position
type TabsTabPosition = { left: number; right: number; top: number; bottom: number };Tabs.Tab.Size
type TabsTabSize = { width: number; height: number };Indicator
A visual indicator that can be styled to match the position of the currently active tab.
Renders a <span> element.
renderBeforeHydrationbooleanfalse
boolean- Description
Whether to render itself before React hydrates. This minimizes the time that the indicator isn’t visible after server-side rendering.
- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Indicator.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Tabs.Indicator.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Indicator.State, ) => ReactElement) | undefined
data-orientation
data-activation-direction
--active-tab-bottom
Indicates the distance on the bottom side from the parent’s container if the tab is active.
--active-tab-height
Indicates the width of the tab if it is active.
--active-tab-left
Indicates the distance on the left side from the parent’s container if the tab is active.
--active-tab-right
Indicates the distance on the right side from the parent’s container if the tab is active.
--active-tab-top
Indicates the distance on the top side from the parent’s container if the tab is active.
--active-tab-width
Indicates the width of the tab if it is active.
Additional Types
Tabs.Indicator.Props
Re-Export of Indicator props as TabsIndicatorProps
Tabs.Indicator.State
type TabsIndicatorState = {
activeTabPosition: Tabs.Tab.Position | null;
activeTabSize: Tabs.Tab.Size | null;
orientation: Tabs.Root.Orientation;
tabActivationDirection: Tabs.Tab.ActivationDirection;
};Panel
A panel displayed when the corresponding tab is active.
Renders a <div> element.
value*Tabs.Tab.Value—
Tabs.Tab.Value- Name
- Description
The value of the TabPanel. It will be shown when the Tab with the corresponding value is active.
- Type
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Tabs.Panel.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Tabs.Panel.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
boolean- Name
- Description
Whether to keep the HTML element in the DOM while the panel is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Tabs.Panel.State, ) => ReactElement) | undefined
data-orientation
data-activation-direction
data-hidden
data-index
Additional Types
Tabs.Panel.Props
Re-Export of Panel props as TabsPanelProps
Tabs.Panel.State
type TabsPanelState = {
hidden: boolean;
transitionStatus: TransitionStatus;
orientation: Tabs.Root.Orientation;
tabActivationDirection: Tabs.Tab.ActivationDirection;
};Tabs.Panel.Metadata
type TabsPanelMetadata = { id?: string; value: Tabs.Tab.Value };