<vega-tab-group id="web-tab-group" gap="size-8" show-close-button="false">
<vega-tab-group-panel id="nav-home">This is the Home tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-profile">Profile tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-contact" >Contact tab</vega-tab-group-panel>
</vega-tab-group>
document.getElementById('web-tab-group').tabItems = [
{ label: 'Home', dataTarget: 'nav-home', prefixIcon: 'home' },
{ label: 'Profile', dataTarget: 'nav-profile' },
{ label: 'Contact', dataTarget: 'nav-contact' },
];
<vega-tab-group id="web-tab-group" gap="size-8" show-close-button="true">
<vega-tab-group-panel id="nav-home">This is the Home tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-profile">Profile tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-contact" >Contact tab</vega-tab-group-panel>
</vega-tab-group>
document.getElementById('web-tab-group').tabItems = [
{ label: 'Home', dataTarget: 'nav-home', prefixIcon: 'home' },
{ label: 'Profile', dataTarget: 'nav-profile' },
{ label: 'Contact', dataTarget: 'nav-contact' },
];
<div class="example-container">
<vega-tab-group id="web-tab-group" gap="size-8" show-close-button="false" class="v-w-full" position-relative-to=".example-container">
<vega-tab-group-panel id="nav-home">This is the Home tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-profile">Profile tab</vega-tab-group-panel>
<vega-tab-group-panel id="nav-contact" >Contact tab</vega-tab-group-panel>
</vega-tab-group>
</div>
document.getElementById('web-tab-group').tabItems = [
{ label: 'Home', dataTarget: 'nav-home', prefixIcon: 'home' },
{ label: 'Profile', dataTarget: 'nav-profile' },
{ label: 'Contact', dataTarget: 'nav-contact' },
{ label: 'Contact2', dataTarget: 'nav-contact4' },
{ label: 'Contact3', dataTarget: 'nav-contact5' },
{ label: 'Contact4', dataTarget: 'nav-contact6' },
{ label: 'Contact5', dataTarget: 'nav-contact7' },
{ label: 'Contact6', dataTarget: 'nav-contact8' },
{ label: 'Contact7', dataTarget: 'nav-contact9' },
{ label: 'Contact8', dataTarget: 'nav-contact10' },
];
<vega-tab-group id="web-tab-group" gap="size-8" show-close-button="true">
<vega-tab-group-panel id="nav-home" is-active="true">
<div class='v-p-size-12'>
<vega-tab-group id='child-tab-group' variant='secondary'>
<vega-tab-group-panel id="child-home">child-home</vega-tab-group-panel>
<vega-tab-group-panel id="child-profile" is-active="true">child-profile</vega-tab-group-panel>
<vega-tab-group-panel id="child-contact">child-contact</vega-tab-group-panel>
</vega-tab-group>
</div>
</vega-tab-group-panel>
<vega-tab-group-panel id="nav-profile">nav-profile</vega-tab-group-panel>
<vega-tab-group-panel id="nav-contact">nav-contact</vega-tab-group-panel>
</vega-tab-group>
document.getElementById('web-tab-group').tabItems = [
{ label: 'Home', dataTarget: 'nav-home', prefixIcon: 'social-instagram' },
{ label: 'Profile', dataTarget: 'nav-profile' },
{ label: 'Contact', dataTarget: 'nav-contact' },
];
document.getElementById('child-tab-group').tabItems = [
{ label: 'Child Home', dataTarget: 'child-home' },
{ label: 'Child Profile', dataTarget: 'child-profile' },
{ label: 'Child Contact', dataTarget: 'child-contact' },
];
Note: The above examples use Vanilla JS. If you would like to use React, Angular, or Vue, please consult Storybook.
The vega-tab-group
component creates a simple tab navigation tool. It can be used for combining different amounts of content on the same page, and may serve well in situations where a carousel may not.
Tabs within the vega-tab-group
will adjust to smaller screen sizes and allow navigation through arrow controls. Controls between the different tabs can be controlled through JavaScript.
Name | Description | Default |
---|---|---|
selected-tab-data-target | The data target of the selected tab. text | |
show-close-button | boolean indicating if the tab show hide is with close button Optional | false |
gap | This specification defines the space in between column elements. The value can be set to any existing spacing design token. 0 size-4 size-8 size-12 size-16 size-20 size-24 size-32 |
size-8 |
tab-items | The tab item shows tab info. Note: This property tabItems can only be set once for initialization and cannot be overridden. {"label": string, "dataTarget": string, "prefixIcon": string}[] |
- |
variant | The tab-group style. primary secondary |
primary |
position-relative-to | Selector of the element that will contain the dropdown. If not provided, the dropdown will be appended to the body. If you encounter a problem with scrolling positioning, modify this property. string |
To include individual panels wihtin the tab group, you will need to use the vega-tab-group-panel
as a child component of vega-tab-group
as shown below. Note that id
is required for this component:
<vega-tab-group id="web-tab-group" gap="size-8" show-close-button="true">
<vega-tab-group-panel id="nav-home">content:nav-home</vega-tab-group-panel>
<vega-tab-group-panel id="nav-profile" is-active="true">content:nav-profile</vega-tab-group-panel>
<vega-tab-group-panel id="nav-contact">content:nav-contact</vega-tab-group-panel>
</vega-tab-group>
Labeling the tabs requires some JavaScript. The dataTarget
poperty references the id of the tab. For example:
document.getElementById('web-tab-group').tabItems = [
{ label: 'Home', dataTarget: 'nav-home', prefixIcon: 'social-instagram' },
{ label: 'Profile', dataTarget: 'nav-profile' },
{ label: 'Contact', dataTarget: 'nav-contact' },
];
As shown above, the tabItems
property can only be set once for initialization purposes, and cannot be reset.
By default, the first tab is selected.
The vegaClick
event is dispatched when a tab is clicked.
document.getElementById("tag_tab_group_id").addEventListener("vegaClick", (e) => {
console.log(e.currentTarget.value) })
For more details, view in Storybook.