Tabs
A tab list that switches between related panels in place.
- Conversations
- 1,284
- Avg. response
- 1.8 s
- Satisfaction
- 92%
Usage guidelines
- Use
Tabswhen the choice swaps the panel it controls, whatever the control looks like. UseSegmentedControlfor a mode or filter applied to content that stays in place, and links for navigation between pages. - Give
TabsListan accessible name witharia-labeloraria-labelledbywhen the page has more than one tab list or no heading introduces it. EachTabsPaneltakes its name from its tab. - Place
TabsIndicatorinsideTabsList. It draws the active underline and slides between tabs; tabs do not draw their own. The list has no baseline of its own; addborder-b border-divider-subtlewhen it sits directly above its panels. - Keep tab labels short and on one line. Disable a tab that is temporarily unavailable rather than removing it, so the set of sections stays stable.
TabsPanelhas no padding. Add spacing on the panel so its inset focus ring keeps clear of the content.
Anatomy
Examples
Disabled tab
disabled on TabsTab keeps the tab in the list at reduced opacity. Arrow keys still move focus to it, but it cannot be activated.
Activate on focus
By default the arrow keys only move focus, and Enter or Space activates the focused tab. Set activateOnFocus on TabsList when panels are cheap to render, so moving focus also switches the panel.
client.create_chat_message(inputs={}, query='Hello', user='abc-123')Controlled value
Control the active tab with value and onValueChange when something outside the tab list changes it, such as a button elsewhere on the page.
Keyboard
| Key | Action |
|---|---|
| Right arroworLeft arrow | Moves focus to the next or previous tab, wrapping at the ends. Disabled tabs take focus. |
| HomeorEnd | Moves focus to the first or last tab. |
| EnterorSpace | Activates the focused tab and shows its panel. |
| Tab | Moves focus from the tab list to the active panel. |
API reference
Tabs
Groups a tab list and its corresponding tab panels. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: TabsRootState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, TabsRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: TabsRootState) => React.CSSProperties | undefined) | No default | |
value | any | No default | |
defaultValue | any | 0 | |
orientation | 'horizontal' | 'vertical' | 'horizontal' | |
onValueChange | ((value: BaseTabs.Tab.Value, eventDetails: BaseTabs.Root.ChangeEventDetails) => void) | No default | |
| Attribute | Description |
|---|---|
data-activation-direction | Values: Indicates the direction of the activation (based on the previous active tab). |
data-orientation | Values: Indicates the orientation of the tabs. |
TabsIndicator
Draws an active underline inside TabsList that slides between tabs. Renders a <span> element.
| Prop | Type | Default | Details |
|---|---|---|---|
renderBeforeHydration | boolean | false | |
className | string | ((state: TabsIndicatorState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, TabsIndicatorState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: TabsIndicatorState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-activation-direction | Values: Indicates the direction of the activation (based on the previous active tab). |
data-orientation | Values: Indicates the orientation of the tabs. |
| Variable | Description |
|---|---|
--active-tab-left | Values: Indicates the distance on the left side from the parent's container if the tab is active. |
--active-tab-right | Values: Indicates the distance on the right side from the parent's container if the tab is active. |
--active-tab-top | Values: Indicates the distance on the top side from the parent's container if the tab is active. |
--active-tab-bottom | Values: Indicates the distance on the bottom side from the parent's container if the tab is active. |
--active-tab-width | Values: Indicates the width of the tab if it is active. |
--active-tab-height | Values: Indicates the height of the tab if it is active. |
TabsList
Groups the individual tab buttons. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
activateOnFocus | boolean | false | |
loopFocus | boolean | true | |
className | string | ((state: TabsListState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, TabsListState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: TabsListState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-activation-direction | Values: Indicates the direction of the activation (based on the previous active tab). |
data-orientation | Values: Indicates the orientation of the tabs. |
TabsPanel
A panel displayed when the corresponding tab is active. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
value required | any | No default | |
keepMounted | boolean | false | |
className | string | ((state: TabsPanelState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, TabsPanelState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: TabsPanelState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-index | Indicates the index of the tab panel. |
data-activation-direction | Values: Indicates the direction of the activation (based on the previous active tab). |
data-orientation | Values: Indicates the orientation of the tabs. |
data-hidden | Present when the panel is hidden. |
data-starting-style | Present when the panel begins animating in. |
data-ending-style | Present when the panel is animating out. |
TabsTab
An individual interactive tab button that toggles the corresponding panel. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: TabsTabState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, TabsTabState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
value required | any | No default | |
disabled | boolean | No default | |
style | React.CSSProperties | ((state: TabsTabState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-activation-direction | Values: Indicates the direction of the activation (based on the previous active tab). |
data-orientation | Values: Indicates the orientation of the tabs. |
data-disabled | Present when the tab is disabled. |
data-active | Present when the tab is active. |