Standard tabs
Creating tabs within your article content doesn’t involve copying and pasting any HTML as the Tabs extension lets you transform standard ordered (<ol>
) and unordered (<ul>
) lists created in the article editor into interactive tabs. This makes it easy for visitors to find what they’re looking and allows content creators to focus on producing helpful content.
If you do ever need to migrate your content you can do so without having to worry about unnecessary markup or inline styles.
The default template is simple, elegant and responsive and will automatically inherit the overall style of your theme. You can add any type of content you like to each tab, including HTML, images, videos and other article formatting styles.
Customized tabs
Customized tabs templates can introduce icons, transition effects and even entirely new layouts like vertical tab links.
Creating tabs
Tabs can be used anywhere in the help center, but often they are used within article content. Our extension allows you to create tabs in several different ways, none of which require you to copy-and-paste any HTML.
The Tabs extension is bundled into all of our themes by default, so you can start using it straight away. The source code can be found within the extensions.(min.)js
file in the theme’s Assets folder.
When creating or updating an article using the Zendesk article editor:
-
Create a numbered () or bulleted list () using the editor toolbar and add the content that you’d like to see in each tab within the list items.
-
Click the Source Code () button in the editor toolbar to view the source code of the page.
-
Add a class name of
.js-tabs
to the list element to convert it into a set of interactive tabs. -
Add a
title
attribute to each list item containing the title you’d like to use for the tab. Alternatively, you can apply a class name of.tab-heading
to an element within the list item and that element’s text content will be used as the tab title.<ul class="js-tabs"> <li title="The first tab title">...</li> <li title="The second tab title">...</li> <li> <h3 class="tab-heading">The third tab title</h3> ... </li> </ul>
The Tabs extension allows you to convert a standard ordered (<ol>
) or unordered (<ul>
) list into an interactive set of tabs using JavaScript:
<ul class="my-tabs">
<li title="The first tab">...</li>
<li title="The second tab">...</li>
<li title="The third tab">...</li>
</ul>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const tabs = [...document.querySelectorAll('.my-tabs')]
tabs.forEach(el => {
new Tabs(el, {
// Options go here
})
})
})
</script>
Options
Options can be passed via data attributes or JavaScript.
Name | Type | Default | Description |
---|---|---|---|
initial | number | 0 | The index of the tab that should be shown on initialization. |
activeClass | text | '' | The class name(s) to apply to the active tab link. |
template | string null | null | The name of the micro-template to use. |
templateData | object | {} | Additional data to provide to the template rendering function. |
When using data attributes, append the option name to data-
and use kebab case instead of camel case. For example, data-template="my-custom-tabs"
instructs the extension to use the custom my-custom-tabs
template when rendering the tabs.
Events
Name | Description |
---|---|
tabs:render | Fires when the tabs markup has been rendered and inserted into the DOM. |
tab:show | Fires when a tab is about to be shown. |
tab:shown | Fires after a tab has been shown. |
tab:hide | Fires when a tab is about to be hidden. |
tab:hidden | Fires after a tab has been hidden. |
Because the original list element is replaced with the HTML from the template, the event contains a reference to the new element:
document.addEventListener('tabs:render', function(e) {
// The newly rendered tabs element
var tabs = e.detail.relatedTarget;
});