Documentation
Feedback
Guides

Tab Layout

The Tab Layout app provides you the needed structure to create different layouts within the store's main one from the use of tabs.

{"base64":"  ","img":{"width":2500,"height":1260,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":391794,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-0.png"}}
Example of an brazilian VTEX store with tabs (Perfumes até 40%off, Presentes, and Best Sellers) displaying different content for users.

Configuration

  1. Add the Tab Layout app to your theme's dependencies in the manifest.json file:

_10
"dependencies": {
_10
+ "vtex.tab-layout": "0.x"
_10
}

Now, you are able to use all the blocks exported by the tab-layout app. Check out the full list below:

Block nameDescription
tab-layout
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":917,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-1.png"}}
for the layout structure, declaring the desired list of tabs and its content.
tab-list
{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABCAIAAAB2XpiaAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAFUlEQVR4nGNIYmD4P7v5c1m8OwMDACBaBI9Db7FhAAAAAElFTkSuQmCC","img":{"src":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-2.png","width":69,"height":20,"type":"svg"}}
Defines the list of tabs to be rendered. It only accepts the tab-list.item block as child.
tab-list.item
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":923,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-3.png"}}
Defines the rendering for a given tab. Notice that it does not define the tab content, which is handled by the tab-content.item block.
tab-list.item.childrenFlexible alternative to tab-list.item. Defines the rendering for a given tab and also accepts any array of blocks as its children.
tab-content
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":923,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-4.png"}}
Defines the list of content to be rendered in each tab. It only accepts the tab-content.item block as child.
tab-content.item
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","length":923,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-tab-layout-5.png"}}
Defines the content for a given tab.
  1. In the desired page tempate, such as store.home, add the tab-layout block:

_10
"store.home": {
_10
"blocks": [
_10
"tab-layout#home"
_10
]
_10
},

  1. Declare the tab-list and the tab-content blocks as tab-layout's children. Do not forget to use the tab-layout's props, for example:

_15
"store.home": {
_15
"blocks": [
_15
"tab-layout#home"
_15
]
_15
},
_15
+ "tab-layout#home":
_15
+ "children": [
_15
+ "tab-list#home",
_15
+ "tab-content#home"
_15
+ ],
_15
+ "props": {
_15
+ "blockClass": "home",
_15
+ "defaultActiveTabId": "home1"
_15
+ }
_15
+ },

  1. Add and then declare the desired tab-list.item blocks as tab-list's children:

_34
"store.home": {
_34
"blocks": [
_34
"tab-layout#home"
_34
]
_34
},
_34
"tab-layout#home":
_34
"children": [
_34
"tab-list#home",
_34
"tab-content#home"
_34
],
_34
"props": {
_34
"blockClass": "home",
_34
"defaultActiveTabId": "home1"
_34
}
_34
},
_34
+ "tab-list#home": {
_34
+ "children": [
_34
+ "tab-list.item#home1",
_34
+ "tab-list.item#home2"
_34
+ ]
_34
+ },
_34
+ "tab-list.item#home1": {
_34
+ "props": {
_34
+ "tabId": "home1",
_34
+ "label": "Home 1",
_34
+ "defaultActiveTab": true
_34
+ }
_34
+ },
_34
+ "tab-list.item#home2": {
_34
+ "props": {
_34
+ "tabId": "home2",
_34
+ "label": "Home 2"
_34
+ }
_34
+ },

  1. Add and then declare the desired tab-content.item blocks as tab-content's children:

_60
"store.home": {
_60
"blocks": [
_60
"tab-layout#home"
_60
]
_60
},
_60
"tab-layout#home":
_60
"children": [
_60
"tab-list#home",
_60
"tab-content#home"
_60
],
_60
"props": {
_60
"blockClass": "home",
_60
"defaultActiveTabId": "home1"
_60
}
_60
},
_60
"tab-list#home": {
_60
"children": [
_60
"tab-list.item#home1",
_60
"tab-list.item#home2"
_60
]
_60
},
_60
"tab-list.item#home1": {
_60
"props": {
_60
"tabId": "home1",
_60
"label": "Home 1",
_60
"defaultActiveTab": true
_60
}
_60
},
_60
"tab-list.item#home2": {
_60
"props": {
_60
"tabId": "home2",
_60
"label": "Home 2"
_60
}
_60
},
_60
+ "tab-content#home": {
_60
+ "children": [
_60
+ "tab-content.item#home1",
_60
+ "tab-content.item#home2"
_60
+ ]
_60
+ },
_60
+ "tab-content.item#home1": {
_60
+ "children": [
_60
+ "carousel#home"
_60
+ ],
_60
+ "props": {
_60
+ "tabId": "home1"
_60
+ }
_60
+ },
_60
+ "tab-content.item#home2": {
_60
+ "children": [
_60
+ "shelf#home",
_60
+ "info-card#home",
_60
+ "rich-text#question",
_60
+ "rich-text#link",
_60
+ "newsletter"
_60
+ ],
_60
+ "props": {
_60
+ "tabId": "home2"
_60
+ }
_60
+ }

Do not forget to also declare the tab-content.item's children blocks in order to properly render the tab content.

tab-layout props

Prop nameTypeDescriptionDefault value
defaultActiveTabIdstringID of the desired tab to be rendered as the default one. If no value is provided, the first tab declared in the theme will be used as default.undefined
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined

tab-list props

Prop nameTypeDescriptionDefault value
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined

tab-list.item props

Prop nameTypeDescriptionDefault value
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined
tabIdstringTab ID of your choosing. It will be used to match the tab to its content (defined by the tab-content.item block).undefined
labelstringDefines the tab's text label.undefined
defaultActiveTabbooleanDefines the item as the default active tab.false

tab-list.item.children props

Prop nameTypeDescriptionDefault value
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined
tabIdstringTab ID of your choosing. It will be used to match the tab to a given content (defined by the tab-content.item block).undefined

tab-content props

Prop nameTypeDescriptionDefault value
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined

tab-content.item props

Prop nameTypeDescriptionDefault value
blockClassstringBlock ID of your choosing to be used in CSS customization.undefined
tabIdstringTab ID of your choosing. It will be used to match the content to a given tab (defined by the tab-list.item / tab-list.item.children blocks).undefined

*Pay attention to the chosen tab ID declared in both tab-list.item and tab-content.item blocks, once it is the key to link a given tab to its content.

Customization

In order to apply CSS customizations in this and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.

CSS Handle
container
contentContainer
contentItem
listContainer
listItem
listItemActive
listItemChildren
listItemChildrenActive
Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page