Tabs

A component for toggling between related panels on the same page.

View as Markdown

Anatomy

Import the component and assemble its parts:

Anatomy

API reference

Root

Groups the tabs and the corresponding panels. Renders a <div> element.

defaultValue

Tabs.Tab.Value

(default:

0

)
Description

The default value. Use when the component is not controlled. When the value is null, no Tab will be selected.

Type

Tabs.Tab.Value

Default

0

value

Tabs.Tab.Value

Name
Description

The value of the currently selected Tab. Use when the component is controlled. When the value is null, no Tab will be selected.

Type

Tabs.Tab.Value

onValueChange

function

Description

Callback invoked when new value is being set.

Type

((value: Tabs.Tab.Value, event: Event | undefined) => void)

orientation

Tabs.Root.Orientation

(default:

'horizontal'

)
Description

The component orientation (layout flow direction).

Type

Tabs.Root.Orientation

Default

'horizontal'

className

string | function

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)

render

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 ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Tabs.Root.State) => ReactElement)

data-orientation

Indicates the orientation of the tabs.

data-activation-direction

Indicates the direction of the activation (based on the previous selected tab).

List

Groups the individual tab buttons. Renders a <div> element.

activateOnFocus

boolean

(default:

true

)
Description

Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using Enter or Spacebar key press.

Type

boolean

Default

true

loop

boolean

(default:

true

)
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

Default

true

className

string | function

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)

render

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 ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Tabs.List.State) => ReactElement)

data-orientation

Indicates the orientation of the tabs.

data-activation-direction

Indicates the direction of the activation (based on the previous selected tab).

Tab

An individual interactive tab button that toggles the corresponding panel. Renders a <button> element.

value

Tabs.Tab.Value

Name
Description

The value of the Tab. When not specified, the value is the child position index.

Type

Tabs.Tab.Value

nativeButton

boolean

(default:

true

)
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (e.g. <div>).

Type

boolean

Default

true

className

string | function

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)

render

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 ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Tabs.Tab.State) => ReactElement)

data-selected

Present when the tab is selected.

data-highlighted

Present when the tab is highlighted.

data-orientation

Indicates the orientation of the tabs.

data-disabled

Present when the tab is disabled.

data-activation-direction

Indicates the direction of the activation (based on the previous selected tab).

Indicator

A visual indicator that can be styled to match the position of the currently active tab. Renders a <span> element.

renderBeforeHydration

boolean

(default:

false

)
Description

Whether to render itself before React hydrates. This minimizes the time that the indicator isn’t visible after server-side rendering.

Type

boolean

Default

false

className

string | function

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)

render

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 ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Tabs.Indicator.State) => ReactElement)

data-orientation

Indicates the orientation of the tabs.

data-activation-direction

Indicates the direction of the activation (based on the previous selected tab).

--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.

Panel

A panel displayed when the corresponding tab is active. Renders a <div> element.

value

Tabs.Tab.Value

Name
Description

The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected. If not provided, it will fall back to the index of the panel. It is recommended to explicitly provide it, as it's required for the tab panel to be rendered on the server.

Type

Tabs.Tab.Value

className

string | function

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)

keepMounted

boolean

(default:

false

)
Description

Whether to keep the HTML element in the DOM while the panel is hidden.

Type

boolean

Default

false

render

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 ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Tabs.Panel.State) => ReactElement)

data-orientation

Indicates the orientation of the tabs.

data-activation-direction

Indicates the direction of the activation (based on the previous selected tab).

data-hidden

Present when the panel is hidden.

data-index

Indicates the index of the tab panel.