Tabs
View as MarkdownA component for toggling between related panels on the same page.
Features
Permalink to heading "Features"- Full keyboard navigation support with arrow keys
- Supports horizontal and vertical orientations
- Supports automatic and manual tab activation modes
- Content is lazy mounted by default
- Supports disabled tabs
<primitives:tabs.root>
<primitives:tabs.list>
<primitives:tabs.trigger />
<primitives:tabs.indicator />
</primitives:tabs.list>
<primitives:tabs.content />
</primitives:tabs.root>
Installation
Permalink to heading "Installation"typo3 ui:add tabs
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Vertical Orientation
Permalink to heading "Vertical Orientation"Display tabs in a vertical layout.
Disabled Tabs
Permalink to heading "Disabled Tabs"Disable specific tabs to prevent interaction.
Manual Activation
Permalink to heading "Manual Activation"Require pressing Enter or Space to activate tabs instead of activating on focus.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
tabs.root
Permalink to heading "tabs.root"Provides shared tabs state and wraps the tab list and panels. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
loopFocus | booleanWhether the keyboard navigation will loop from last tab to first, and vice versa. | No | true |
defaultValue | stringThe initial selected tab value when rendered. Use when you don't need to control the selected tab value. | No | - |
orientation | Enum\OrientationThe orientation of the tabs. | No | Horizontal |
activationMode | Enum\TabsActivationModeThe activation mode of the tabs. | No | Automatic |
virtualFocus | booleanWhether the tabs use virtual focus instead of a roving tabindex. Triggers then receive no DOM focus: arrow keys only move the focused value and every trigger and panel stays out of the tab order. Useful when the tabs live inside another widget that manages focus, like a combobox. | No | false |
deselectable | booleanWhether the active tab can be deselected when clicking on it. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-tabs-root | <uid> |
data-orientation | The orientation of the tabs |
data-focus | Present when focused |
tabs.list
Permalink to heading "tabs.list"Groups the tab triggers. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-tabs-list | <uid> |
data-focus | Present when focused |
data-orientation | The orientation of the list |
tabs.trigger
Permalink to heading "tabs.trigger"Activates a tab and focuses its panel. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the tab. | Yes | - |
disabled | booleanWhether the tab is disabled. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-tabs-trigger | <uid> |
data-orientation | The orientation of the trigger |
data-disabled | Present when disabled |
data-value | The value of the item |
data-selected | Present when selected |
data-focus | Present when focused |
data-ssr | Present when not rendered in the browser. Useful for ssr styling |
tabs.indicator
Permalink to heading "tabs.indicator"Displays the active tab indicator. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-tabs-indicator | <uid> |
data-orientation | The orientation of the indicator |
tabs.content
Permalink to heading "tabs.content"Displays the panel content for a tab. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the tab. | Yes | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-tabs-content | <uid> |
data-selected | Present when selected |
data-orientation | The orientation of the content |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
value | string | null | The current value of the tabs. |
focusedValue | string | null | The value of the tab that is currently focused. |
setValue | (value: string) => void | Sets the value of the tabs. |
clearValue | VoidFunction | Clears the value of the tabs. |
setIndicatorRect | (value: string) => void | Sets the indicator rect to the tab with the given value |
syncTabIndex | VoidFunction | Synchronizes the tab index of the content element. Useful when rendering tabs within a select or combobox |
focus | VoidFunction | Set focus on the selected tab trigger |
selectNext | (fromValue?: string) => void | Selects the next tab |
selectPrev | (fromValue?: string) => void | Selects the previous tab |
getTriggerState | (props: TriggerProps) => TriggerState | Returns the state of the trigger with the given props |
getContentState | (props: ContentProps) => ContentState | Returns the state of the content with the given props |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
Tab | When focus moves onto the tabs, focuses the active trigger. When a trigger is focused, moves focus to the active content. |
ArrowDown | Moves focus to the next trigger in vertical orientation and activates its associated content. |
ArrowRight | Moves focus to the next trigger in horizontal orientation and activates its associated content. |
ArrowUp | Moves focus to the previous trigger in vertical orientation and activates its associated content. |
ArrowLeft | Moves focus to the previous trigger in horizontal orientation and activates its associated content. |
Home | Moves focus to the first trigger and activates its associated content. |
End | Moves focus to the last trigger and activates its associated content. |
EnterSpace | In manual mode, when a trigger is focused, moves focus to its associated content. |